write a program in Java to enter a number and check whether it is Armstrong number or not
Answers
Answer:
here is your verified answer
Explanation:
import java.util.*;
class Number
{
public static void main(String args)
{
Scanner sc=new Scanner(System.in);
int x,sum=0;
System.out.println("enter a number");
int n=sc.nextInt();
x=n;
while(n!=0)
{
int r=n%10
sum=sum+(r*r*r);
n=n/10;
}
if(x==sum)
System.out.println("Armstrong number");
else
System.out.println("not an armstrong number");
}
}
Question :-
A program in java to enter and check whether a number is Armstrong number or not.
Answer :-
//Program to check whether Armstrong number or not
public class Armstrong_Number
{
void display()
{
int n;
int a,number,sum = 0;
number = n;
while(n>0)
{
a = n%10;
sum = sum + a*a*a;
n = n/10;
}
if(number == sum)
System.out.println("The number"+number +" is an Armstrong number");
else
System.out.println("The number"+number +" is not an Armstrong number");
}//end of method
}//end of class
Hope it helps ✌️