Skip to content

Commit c7e1b04

Browse files
committed
Add Armstrong_Number.java
1 parent acb408b commit c7e1b04

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: Armstrong_Number.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Armstrong_Number {
2+
3+
// Optimal Approach
4+
static boolean armstrong (int n) {
5+
int sum = 0;
6+
int dup = n;
7+
while (n > 0) {
8+
int lastDigit = n % 10;
9+
sum = sum + (lastDigit * lastDigit * lastDigit);
10+
n = n / 10;
11+
}
12+
if (dup == sum) {
13+
return true;
14+
}
15+
else {
16+
return false;
17+
}
18+
}
19+
20+
// Main Function
21+
public static void main(String[] args) {
22+
boolean result = armstrong(170);
23+
System.out.println(result);
24+
}
25+
}
26+

0 commit comments

Comments
 (0)