Thursday, 4 February 2016

Armstrong program in Java

Armstrong program in Java

Hello friends; Hitesh is here today we write on simple code for Armstrong program in Java. Here the main things are to check the given number is Armstrong or not by using Java programming. For this program no need new concept just follow the same algorithm like C language only changes the syntax of C to Java Language.

Armstrong program in Java

Java Program to Check Number is Armstrong or Not

class ArmstrongNumber
{
public static void main(String[] args)
 {
int c=0,a,temp;
int n=153; // check armstrong for 153
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c)
System.out.println("This is Armstrong number");
else
System.out.println("Not Armstrong number");
}
}

Output:

This is Armstrong number
I hope this code is helpful for you; for more detail and other same code visit our website.

No comments:

Post a Comment