Write a program to check a number is Armstrong or not in java

 Write a program to check a number is Armstrong or not in java

public class Armstrong
{
    public static void main(String args[]){
     int num=153,digit=0,temp,last;
     double s=0;
     temp=num;
     while(temp!=0){
         digit++;
         temp=temp/10;
        }
     temp=num;
     while(temp!=0){
         last=temp%10;
         s=s+Math.pow(last,digit);
         temp=temp/10;
        }
     if(num==s){
        System.out.println("Armstrong");
        }else{
        System.out.println("Not Armstrong");
        }
     
    }
}
Output
Armstrong

Comments

Popular posts from this blog

Make a GST Calculator using HTML and JavaScript

How to make simple bill maker by using python tkinter

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java