-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrongNum.Java
More file actions
50 lines (40 loc) · 1.16 KB
/
ArmstrongNum.Java
File metadata and controls
50 lines (40 loc) · 1.16 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package challanges;
import java.util.Scanner;
public class ArmstrongNum{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Welcome to Check Armstrong Cheacker\n");
System.out.print("Enter Number : ");
int UserInput = input.nextInt();
input.close();
int digits = DigitsCount(UserInput);
int ActualNum = UserInput;
int result = 0;
while(UserInput > 0) {
int digit = UserInput % 10;
result = result + power(digit, digits);
UserInput = UserInput / 10;
}
if(result == ActualNum){
System.out.print("Armstrong Number");
}else{
System.out.print("Not an Armsstrong Number");
}
}
public static int DigitsCount(int Num) {
int count = 0;
while(Num > 0) {
count++;
Num = Num / 10;
}
return count;
}
public static int power(int num, int power){
int result = 1;
while(power > 0){
result = result * num;
power--;
}
return result;
}
}