-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNum.java
More file actions
31 lines (25 loc) · 820 Bytes
/
ArmstrongNum.java
File metadata and controls
31 lines (25 loc) · 820 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
// To find Armstrong Number between two given number.
import java.util.Scanner;
public class ArmstrongNum {
public static void main(String[] args) {
int num1, num2;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number: ");
num1 = sc.nextInt();
System.out.println("Enter the second number: ");
num2 = sc.nextInt();
for (int i = num1; i < num2; i++) {
int check, rem, sum = 0;
check = i;
while (check != 0) {
rem = check % 10;
sum = sum + (rem * rem * rem);
check = check / 10;
}
if (sum == i) {
System.out.println("" + i + " is an Armstrong number.");
}
}
sc.close();
}
}