-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.java
More file actions
41 lines (34 loc) · 890 Bytes
/
Copy pathArmstrong.java
File metadata and controls
41 lines (34 loc) · 890 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
39
40
41
package java_basic.small_programs;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Armstrong {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = 0;
try {
System.out.println("Enter the number : ");
num = Integer.parseInt(br.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
isArmstrongNumber(num);
}
private static void isArmstrongNumber(int num) {
int number = num;
int sum = 0;
int single = 0;
while(num > 0) {
single = num%10;
sum = sum + single*single*single;
num = num/10;
}
if(number == sum) {
System.out.println(sum+" is a armstrong number");
} else {
System.out.println(sum+" is not a armstrong number");
}
}
}