//Amstrong Number Generation import java.io.*; class Amstrong { int sum=0,rem,t; void check(int num) { t=num; while( num !=0 ) { rem= num % 10; sum = sum + rem*rem*rem; num = num/10; } if( sum == t) System.out.println(" The number is an amstrong number"); else System.out.println("The given number is not an amstrong number"); } public static void main(String args[])throws IOException { Amstrong am= new Amstrong(); int n; BufferedReader b= new BufferedReader(new InputStreamReader(System.in)); System.out.println(" Enter the number:"); n=Integer.parseInt(b.readLine()); am.check(n); } }
Output: |
---|
1.Enter the number: |
134 |
The given number is not an amstrong number |
2.Enter the number: |
153 |
The number is an amstrong number |