-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong.java
More file actions
35 lines (26 loc) · 983 Bytes
/
armstrong.java
File metadata and controls
35 lines (26 loc) · 983 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
import java.util.Scanner;
public class armstrong {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the lower limit: ");
int lower = input.nextInt();
System.out.print("Enter the upper limit: ");
int upper = input.nextInt();
System.out.println("Armstrong numbers between " + lower + " and " + upper + " are:");
for (int num = lower; num <= upper; num++) {
if (isArmstrong(num)) {
System.out.println(num);
}
}
}
public static boolean isArmstrong(int number) {
int originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += remainder * remainder * remainder;
originalNumber /= 10;
}
return result == number;
}
}