Java program to check whether the user input is armstrong number or not


Program
import java.util.*; public class CheckArmstrong { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter the number to check whether a number is armstrong or not"); int num = s.nextInt(); int n, rem, result = 0; n = num; while (n != 0) { rem = n % 10; result += Math.pow(rem, 3); n /= 10; } if(result == num) System.out.println(num + " is an Armstrong number."); else System.out.println(num + " is not an Armstrong number."); } }
Input
Output