Armstrong Number in JAVA



///Chechk a number is Armstrong or not.................


package SolveProblem;

import java.util.Scanner;

public class ArmstrongNumber {
    static Scanner myScanner=new Scanner(System.in);
    public static void main(String[] args) {
        int n,num,temp;
      
        n=myScanner.nextInt();
      
        num=n;
        int sum=0;
        while(num!=0){
            int r=num%10;
            sum=sum+r*r*r;
            num=num/10;
        }
        if (sum==n) {
            System.out.println("Armstrong Number");
        }else{
            System.out.println("Not Armstrong");
        }
    }

}
 //371 is Armstrong number

//25 is not Armstrong number

No comments:

Post a Comment