Write a Java Program to find Whether it is Armstrong Number or not |EasyCoding45

Write a Java Program to find Whether it is Armstrong Number or not



In This Tutorial We are going to learn how we can Write a Java Program to find Whether it is Armstrong Number or not.


Definition :-

  • An Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself.
  • example :- 153 is an Armstrong number.


Program :- (Write a Java Program to find Whether it is Armstrong Number or not)

import java.util.*;

class armstrong
{
int rem;

int sum;

int temp;

public void find(int num)
{
temp=num;

while(num!=0)
{
rem=num%10;

sum=sum+(rem*rem*rem);

num=num/10;
}
if(temp==sum)
                   {

System.out.println("It is Armstrong Number ");

                    }
else
                    {

System.out.println("It Is Not Armstrong Number ");

                    }
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter Number to Find Whether it is Armstrong or not ?");

int no=sc.nextInt();

armstrong as=new armstrong();

as.find(no);

}
}


Output:-




Comments