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


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: