import java.util.*;
import java.io.*;
class armstrong
{
public static void main(String args[])throws Exception
{
int r,sum=0;
System.out.println("Enter a number");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(k.readLine());
int k1=n;
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==k1)
System.out.println(k1+" is an armstrong number");
else
System.out.println(k1+" is not an armstrong number");
}
}
Output:
Enter a number
153
153 is an armstrong number
import java.io.*;
class armstrong
{
public static void main(String args[])throws Exception
{
int r,sum=0;
System.out.println("Enter a number");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
int n= Integer.parseInt(k.readLine());
int k1=n;
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==k1)
System.out.println(k1+" is an armstrong number");
else
System.out.println(k1+" is not an armstrong number");
}
}
Output:
Enter a number
153
153 is an armstrong number