Armstrong Number or not in Java

Armstrong Number or not :
Armstrong number is a number which is equal to the sum of cubes of its digits.for example 0, 1,4, 153, 370, 371, 407,8208 etc.

public class armstrong {
public static void main(String args[]){
int n,sum=0,t,r;
System.out.println(“enter the n value: “);
Scanner k=new Scanner(System.in);
n=k.nextInt();
t=n;
while(n!=0){
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(t==sum)
System.out.println(“the given number is Arm strong number:”+t);
else
System.out.println(“the given number is not a Arm strong number:”+t);
}
}

OutPut:    
 Enter the n value:
153
The given number is strong number : 153

Related Programs Below:
Write a program the given number is even or odd in java?
Write a program for the given number is Fibonacci or not in java?
Prime numbers in Java?
Palindrome number Program in java?
Armstrong Number or not in Java?
Write a program for the given number is strong Number or Not  in java?
Write a program swapping two numbers without using third variable in java ?
Swapping of two numbers using third variable in java?

Leave a Reply

Your email address will not be published.