Search For

Armstrong Number or Not

Flag Hide Line Nos
Flagging a Snippet, takes the snippet to Moderator Attention;


0
//Amstrong number or not
import java.io.*;
class Amstrongmain
{
public static void main(String args[])throws IOException
{
int num , sum=0;
int t,rem;
BufferedReader b= new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter the number:");
num=Integer.parseInt(b.readLine());
t=num;
while( num > 0 )
{
rem= num % 10;
sum = sum + rem*rem*rem;
num = num/10;
}
if( sum == t)
System.out.println(" The given number is an amstrong number");
else
System.out.println("The given number is not an amstrong number");
}
}


Output:
Enter the number:
2343
The given number is not an amstrong number
Enter the number:
1

Vote! You feel this code is working like charm ? Go a head Login and Press up arrow.
Didn't work ?, press down arrow and let us know the error in comments

Comments