Armstrong.java
Aim:
To find armstrong number
Source code:
import java.lang.*;
import java.util.*;
class Armstrong
{
public static void main(String args[])
{
int sum=0,n,digit,m;
Scanner input=new Scanner(System.in);
System.out.println("Enter value for n");
n=input.nextInt();
m=n;
while(n!=0)
{
digit=n%10;
sum=sum+(digit*digit*digit);
n=n/10;
}
if(m==sum)
System.out.println("Armstrong");
else
System.out.println("Not Armstrong");
}
}
Output-1:
Enter value for n
153
Armstrong
Output-2:
Enter value for n
134
Not Armstrong
No comments:
Post a Comment