Armstrong number in Java.



Following is the required program.

 Live Demo

public class Tester {
   public static void main(String[] args) {
      int c = 0, a, temp;
      int m = 153;
      int n = m;
      temp = n;
      while (n > 0) {
         a = n % 10;
         n = n / 10;
         c = c + (a * a * a);
      }
      if (temp == c)
         System.out.println(m + " is an armstrong number");
      else
         System.out.println(m + "is not an armstrong number");
   }
}

Output

153 is an armstrong number
Rishi Raj
Rishi Raj

I am a coder


Advertisements