-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNumber.java
More file actions
31 lines (27 loc) · 919 Bytes
/
ArmstrongNumber.java
File metadata and controls
31 lines (27 loc) · 919 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
import java.util.Scanner;
// List of ArmstrongNumber number
public class ArmstrongNumber {
public static void main(String[] args) {
try (Scanner input = new Scanner(System.in)) {
int start, end, count = 0;
System.out.println("Enter start number: ");
start = input.nextInt();
System.out.println("Enter end number: ");
end = input.nextInt();
for (int i = start; i <= end; i++) {
int temp, r, result = 0;
temp = i;
while (temp != 0) {
r = temp % 10;
result = result + r * r * r;
temp = temp / 10;
}
if (i == result) {
System.out.print(result + " ");
count++;
}
}
System.out.println("\n" + count);
}
}
}