Skip to content

Commit 1369f88

Browse files
authored
Armstrong number added
1 parent 084a81a commit 1369f88

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Number Theory/ArmstrongNumber.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers;
2+
/* 153 = (1*1*1)+(5*5*5)+(3*3*3)
3+
where:
4+
(1*1*1)=1
5+
(5*5*5)=125
6+
(3*3*3)=27
7+
So:
8+
1+125+27=153 */
9+
10+
public class ArmstrongNumber {
11+
public ArmstrongNumber() {
12+
}
13+
14+
public static void main(String[] args) {
15+
Scanner in = new Scanner(System.in);
16+
int num = in.nextInt();
17+
int temp = num;
18+
19+
int result;
20+
for(result = 0; 0 < num; num /= 10) {
21+
int rem = num % 10;
22+
result += rem * rem * rem;
23+
}
24+
25+
if (temp == result) {
26+
System.out.println(temp + " is a armstrong number");
27+
} else {
28+
System.out.println(temp + " is not a armstrong number");
29+
}
30+
31+
}
32+
}

0 commit comments

Comments
 (0)