We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent acb408b commit c7e1b04Copy full SHA for c7e1b04
Armstrong_Number.java
@@ -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