write a program in java to enter a number and check whether it is an armostrong number or not. ( an Armstrong number is that inbthe sum of the cubes of its digits is equal to the number).
Answers
Answered by
5
import java.util.*;
public class Armstrong
{
public static void main(String args[ ])
{
Scanner in = new Scanner(System.in);
int n,a,num,s=0;
num=n;
System.out.println("Enter the number");
n=in.nextInt();
while(n>0)
{
a=n%10;
s=s+a*a*a;
n=n+10;
}
if(num==s)
System.out.println("The number"+num+"is an Armstrong Number");
else
System.out.println("The number"+num+"is not an aArmstrong number");
}
}
Similar questions
Math,
4 months ago
Math,
4 months ago
Hindi,
4 months ago
Chemistry,
8 months ago
World Languages,
8 months ago
Social Sciences,
1 year ago