// simple_armstrong_number
import java.io.*;
class simple_armstrong_number
{
public static void main(String args[])
{
try
{
int rem,n,no,div,arm=0;
DataInputStream cin=new DataInputStream(System.in);
System.out.println("enter number to check it is armstrong or not");
n=Integer.parseInt(cin.readLine());
no=n;
while(n!=0)
{
rem=n%10;
div=n/10;
arm=arm+(rem*rem*rem);
n=div;
}
if(arm==no)
{
System.out.println(no+" is armstromg");
}
else
{
System.out.println(no+" is not armstromg");
}
}
catch(Exception e)
{
System.out.println("wrong data");
}
}
}
No comments:
Post a Comment