✅ What is an Armstrong Number?
A number is an Armstrong number if:
sum of cubes of its digits = the number itself (for 3-digit numbers)
Example: 153 = 1³ + 5³ + 3³ = 153
✅ Java Code:
import java.util.Scanner;
public class ArmstrongNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input a number
System.out.print(“Enter a number: “);
int number = sc.nextInt();
int original = number;
int result = 0;
while (number != 0) {
int digit = number % 10;
result += digit * digit * digit; // cube of digit
number = number / 10;
}
if (result == original)
System.out.println(original + ” is an Armstrong number.”);
else
System.out.println(original + ” is not an Armstrong number.”);
}
}
📌 Sample Input/Output:
Input: 153
Output: 153 is an Armstrong number.