- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNumber.java
More file actions
Latest commit
28 lines (26 loc) · 775 Bytes
/
Copy pathArmstrongNumber.java
File metadata and controls
28 lines (26 loc) · 775 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
importjava.util.Scanner;
publicclassArmstrongNumber{
publicstaticvoidmain(String[] args){
Scannersc = newScanner (System.in);
System.out.print("Enter a number: ");
intnumber = sc.nextInt();
sc.close();
intoriginalNum = number,sum =0,digits =0,temp = number;
while(temp>0){
temp /= 10;
digits++;
}
temp = number;
while(temp > 0){
intdigit = temp %10;
sum += Math.pow(digit,digits);
temp /= 10;
}
if(sum==originalNum){
System.out.println(originalNum + " is a armstrong number");
}
else{
System.out.println(originalNum + " is not a armstrong number");
}
}
}