Here we are going to write a program to check a number is ArmStrong or not ?
Number is ArmStrong or not ?
[java]
import java.util.Scanner;
public class ArmStrongNumber {
public static void main(String a[]) {
int remainder, dividor, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Number");
int input = sc.nextInt();
int temp = input;
while (input > 0) {
remainder = input % 10;
input = input / 10;
sum = sum + (remainder * remainder * remainder);
}
if (sum == temp) {
System.out.println("ArmStrong Number");
} else {
System.out.println("Not an ArmStrong Number");
}
}
}
[/java]
Output :
Enter a Number 371 ArmStrong Number Enter a Number 180 Not an ArmStrong Number
Happy Learning 🙂