-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathArmstrong.java
More file actions
27 lines (23 loc) · 787 Bytes
/
Armstrong.java
File metadata and controls
27 lines (23 loc) · 787 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
/*Write a Java program to check if a given number is an Armstrong number or not.
Here's an example of the expected input and output:
Input number: 153
Output: "Yes, the number is an Armstrong number."
*/
import java.util.*;
public class Armstrong {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String num = sc.nextLine();
int sum = 0;
for (int i = 0; i < num.length(); i++) {
sum+= Math.pow(Integer.parseInt(String.valueOf(num.charAt(i))),3);
}
if(sum == Integer.parseInt(num))
{
System.out.println("Yes, the number is an Armstrong number.");
}
else{
System.out.println("No, the number is not an Armstrong number.");
}
}
}