Find Out The Given Number Is Armstrong Number Or Not.
import java.util.*;
public class ArmstrongNumber {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Input The Number: ");
int n = sc.nextInt();
int goal = n,p = n;
double b = 0,sum = 0;
while(p>0){
p = p/10;
b++;
}
while(n>0){
int tem = n%10;
sum = sum + Math.pow(tem,b);
n = n/10;
}
if(goal == sum){
System.out.println("\nThe Number Is Armstrong Number\n");
}
else{
System.out.println("\nThe Number Is Not Armstrong Number\n");
}
}
}
The output of the program:
No comments