forked from SuriyaaVijay/code-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmstrong_number
29 lines (24 loc) · 831 Bytes
/
Armstrong_number
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
import java.util.Scanner;
public class ArmstrongNumber {
public static boolean isArmstrongNumber(int num) {
int originalNum = num;
int numDigits = (int) Math.log10(num) + 1;
int armstrongSum = 0;
while (num > 0) {
int digit = num % 10;
armstrongSum += Math.pow(digit, numDigits);
num /= 10;
}
return armstrongSum == originalNum;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int userNum = scanner.nextInt();
if (isArmstrongNumber(userNum)) {
System.out.println(userNum + " is an Armstrong number.");
} else {
System.out.println(userNum + " is not an Armstrong number.");
}
}
}