2024-08-10 09:47:35 +05:30
|
|
|
import java.util.Scanner;
|
2024-08-10 11:20:04 +05:30
|
|
|
import java.lang.Math;
|
2024-08-10 09:47:35 +05:30
|
|
|
|
|
|
|
class Armstrong{
|
|
|
|
public static void main(String args[]){
|
|
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
|
|
|
|
int a,b,digit;
|
|
|
|
int digisum=0;
|
2024-08-10 11:20:04 +05:30
|
|
|
int c=0;
|
2024-08-10 09:47:35 +05:30
|
|
|
|
|
|
|
System.out.println("Enter the number you went to check for Armstrong-ness:");
|
|
|
|
a = sc.nextInt();
|
2024-08-10 11:20:04 +05:30
|
|
|
|
|
|
|
b = a;
|
|
|
|
|
|
|
|
while(b!=0){
|
|
|
|
c++;
|
|
|
|
b/=10;
|
|
|
|
}
|
2024-08-10 09:47:35 +05:30
|
|
|
|
|
|
|
b = a;
|
|
|
|
|
|
|
|
while(b!=0){
|
|
|
|
digit = b%10;
|
2024-08-10 11:20:04 +05:30
|
|
|
digisum += Math.pow(digit, c);
|
2024-08-10 09:47:35 +05:30
|
|
|
b /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(digisum == a){
|
|
|
|
System.out.println("The number is an armstrong number.");
|
|
|
|
}else{
|
|
|
|
System.out.println("The number is not an armstrong number.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|