27 lines
663 B
Java
27 lines
663 B
Java
import java.util.Scanner;
|
|
|
|
class Armstrong {
|
|
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
System.out.println("Enter a number");
|
|
|
|
int n = sc.nextInt();
|
|
int b = String.valueOf(n).length();
|
|
int sum = 0;
|
|
int temp = n;
|
|
while (temp > 0) {
|
|
int r = temp % 10;
|
|
sum += Math.pow(r, b);
|
|
temp /= 10;
|
|
}
|
|
if (sum == n) {
|
|
System.out.println("The given number is an Armstrong Number.");
|
|
} else {
|
|
System.out.println("The given number is not an Armstrong Number.");
|
|
}
|
|
sc.close();
|
|
}
|
|
}
|