Enter the integer you want to check as an input. Now we use modulos and division operations along with loops and if else statements to get the output.
Here is the source code of the Java Program to Check If a Given Number is ArmStrong Number. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class ArmStrong
public static void main(String args)
int n, count = 0, a, b, c, sum = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter any integer you want to check:");
n = s.nextInt();
a = n;
c = n;
while(a > 0)
a = a / 10;
while(n > 0)
b = n % 10;
sum = (int) (sum+Math.pow(b, count));
n = n / 10;
if(sum == c)
System.out.println("Given number is Armstrong");
System.out.println("Given number is not Armstrong");
$ javac ArmStrong.java $ java ArmStrong Enter any integer you want to check:153 Given number is Armstrong
Sanfoundry Global Education & Learning Series – 1000 Java Programs.