-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.java
More file actions
30 lines (30 loc) · 883 Bytes
/
Armstrong.java
File metadata and controls
30 lines (30 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.
//For instance, a 3 digit number will be considered an Armstrong number if the sum of the cubes of its digits is equal to the number itself.
//For example, 153 is an Armstrong number, as 1*3 + 53 + 3*3 = 153
import java.util.*;
public class Armstrong
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number to check if it's Armstrong no or not");
int num=in.nextInt();
int temp=num;
int sum=0;
while(temp>0)
{
int rem=temp%10;
int cal=rem*rem*rem;
sum=sum+cal;
temp=temp/10;
}
if(num==sum)
{
System.out.println("The number is an Armstrong number");
}
else
{
System.out.println("The number is not an Armstrong number");
}
}
}