package javaPrograms;
import java.util.Scanner;
public class ArmstrongNumber
{
public static void main(String a[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter no to verify Armstrong no.");
int n=sc.nextInt();
int originalNumber=n;
int resultNumber = 0;
while(n>0)
{
int r=n%10;
n=n/10;
resultNumber=resultNumber+r*r*r;
}
if(originalNumber==resultNumber)
{
System.out.println("No is Armstrong");
}
else
{
System.out.println("No is not Armstrong");
}
}
}
Output
-----------------------------------------------------------------------------------------------------------------------
enter no to verify armstrong no.
153
No is Armstrong
import java.util.Scanner;
public class ArmstrongNumber
{
public static void main(String a[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter no to verify Armstrong no.");
int n=sc.nextInt();
int originalNumber=n;
int resultNumber = 0;
while(n>0)
{
int r=n%10;
n=n/10;
resultNumber=resultNumber+r*r*r;
}
if(originalNumber==resultNumber)
{
System.out.println("No is Armstrong");
}
else
{
System.out.println("No is not Armstrong");
}
}
}
Output
-----------------------------------------------------------------------------------------------------------------------
enter no to verify armstrong no.
153
No is Armstrong
0 Comments