Archive
Posts Tagged ‘Armstrong number’
Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number) – Q11
January 6, 2009
Leave a comment
Q11: Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number)
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
For example: 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
class armg{ public static void main(String args[]){ int num; num = Integer.parseInt(args[0]); int res=0, x, n; while(num != 0){ x = num % 10; res += x*x*x; num /= 10; } n = Integer.parseInt(args[0]); if(n == res) System.out.println(args[0] + " is Armgstrong Number"); else System.out.println(args[0] + " is not Armgstrong Number"); } }
… from College notes (BCA/MCA assignments):
Categories: Java
Armstrong number, Java Basic Programs