Skip to content

Commit 482f63b

Browse files
Add files via upload
1 parent 33d233c commit 482f63b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Conditional Statement/ArmStrong.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Scanner;
2+
public class ArmStrong {
3+
static int xpown (int x, int n) {
4+
if (n==0) {
5+
return 1;
6+
}
7+
return x * xpown(x, n-1);
8+
}
9+
10+
public static void main(String[] args) {
11+
// Write your code here
12+
Scanner sc = new Scanner(System.in);
13+
String str = sc.next();
14+
int num = Integer.parseInt(str);
15+
int res=0;
16+
17+
for (int i=0; i<str.length(); i++) {
18+
int current = Character.getNumericValue(str.charAt(i));
19+
res = xpown(current, str.length()) + res;
20+
}
21+
22+
System.out.print((res == num)? true : false);
23+
}
24+
}

0 commit comments

Comments
 (0)