-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrongNum.java
More file actions
38 lines (29 loc) · 858 Bytes
/
Copy patharmstrongNum.java
File metadata and controls
38 lines (29 loc) · 858 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
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class armstrongNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
int originalNum = num;
int temp = num;
int digits = 0;
int sum = 0;
while (temp > 0) {
digits++;
temp = temp / 10;
}
temp = num;
while (temp > 0) {
int digit = temp % 10;
sum += Math.pow(digit, digits);
temp = temp / 10;
}
// Check Armstrong number
if (sum == originalNum) {
System.out.println(originalNum + " is an Armstrong Number");
} else {
System.out.println(originalNum + " is not an Armstrong Number");
}
sc.close();
}
}