Home > Java > Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number) – Q11

Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number) – Q11


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):


  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.