Armstrong Number

This program checks whether a number is an Armstrong number.
It's often asked in coding rounds to test number logic.

Java Code
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = sc.nextInt();
        int original = num;
        int result = 0;

        while (num != 0) {
            int digit = num % 10;
            result += digit * digit * digit; // cube of each digit
            num /= 10;
        }

        if (result == original)
            System.out.println(original + " is an Armstrong number.");
        else
            System.out.println(original + " is not an Armstrong number.");
    }
}
      
Output
Enter a number: 153
153 is an Armstrong number.