Wednesday, July 26, 2017

Amstrong number example in java

public class Amstrong {

    public static void main(String[] args) {

 int n = 153;

 if (isAmstrong(n)) {
     System.out.println("yes");
 } else {
     System.out.println("no");
 }
    }

    private static boolean isAmstrong(int n) {

 int result = 0;
 int number = n;

 while (n != 0) {
     int remainder = n % 10;
     result = result + remainder * remainder * remainder;
     n = n / 10;
 }
 if (result == number) {
     return true;
 } else {
     return false;
 }
    }
}