21. Number is Armstonrg or not

       Armstorng no : If the sum of the digits of the cube of number is equal to original number then it is armstorng number .

      ex : take number n = 153;

          if  3*3*3 + 5*5*5 + 1*1*1 = 153 (i.e. same  number ,n )

          then, the number is Armstorng number.


 int n,r;
int sum=0;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
int store = n // to store the number ;
while(n>0)
{
r=n%10;
sum=sum+r*r*r; //sum of the cuber of the number
n=n/10;
}
System.out.println(sum);
if (sum==store)
{
System.out.println(store +" is Armstrong no");
}
else
System.out.println(store + " is not Armstrong no");
}

23564

440

23564 is not Armstrong no


Process finished with exit code 0

          

Comments

Popular posts from this blog

How to implement animation or lottie files in android.

Dice Roller App using Java

22. Reverse the number and find number is Pallindrome or not.