Write java program to find given number is armstrong number or not.

import java.util.Scanner;
class Armstrong
{
int n,org;
        
        //To initialize values
Armstrong(int no)
{
n=no;
org=n;
}

        //To check number is armstrong number or not. 
void arm()
{
int s=0,r=0;
while(n>0)
{
r=n%10;
s=s+r*r*r;
n=n/10;
}
if(s==org)
{
System.out.println(s+" is Armstrong ");
else
{
System.out.println(s+" is not Armstrong ");
}
}
}

//To create object 
class TestArmstrong
{
public static void main(String args[])
{
int n;
Scanner input=new Scanner(System.in);
System.out.println("\n Enter number :- ");
n=input.nextInt();
Armstrong obj=new Armstrong(153);
obj.arm();
}
}

0 Comments