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

Calculate Compound Interest in JavaScript

How to make simple bill maker by using python tkinter

Admin Login Page Using HTML and CSS