program to check Armstrong number in java


Founder of Java Engineering Programs. Follow me on Google+ ,Linked in.

You may also like...

Leave a Reply

2 Comments on "program to check Armstrong number in java"

Notify of
Sort by:   newest | oldest | most voted

Another way to check if a number is an Armstrong number by taking user input..


import java.util.Scanner;

class Armstrong{
public static void main(String args[]){
System.out.println(“Enter a number”);

Scanner sc = new Scanner(;
String a = sc.nextLine();
int size = a.length();

System.out.println(“Length of the input number is = ” + size);

int num = Integer.parseInt(a);
int n = num;
int check=0,remainder;

while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,size);
num = num / 10;
if(check == n)
System.out.println(n+” is an Armstrong Number”);
System.out.println(n+” is not an Armstrong Number”);