Programming Examples

Java program to pass an integer as argument and check whether it is Armstrong number or not


Write a program to pass an integer as argument and check whether it is Armstrong number or not. Numbers whose sum of the cube of its digit is equal to the number itself is called Armstrong numbers. Example 153=13+53 +33.

Solution

class Armstrong
{
	public static void main(int a)
	{
		int i,d,s=0;
		for(i=a;i>9;i=i/10)
		{
			d=i%10;
			s=s+d*d*d;
		}
		if(s==a)
			System.out.println("Armstrong Number");
		else
			System.out.println("Not an Armstrong Number");
	}
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz