17+ Java Armstrong Checker & Finder Examples

This post contains a total of 17+ Hand-Picked Java Armstrong Number Checker & Finder Program Examples with Source Code. All the Armstrong Number Checker & Finder programs are made using Java Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Navoneel

Made by Navoneel. A simple java program to find if a three digit number is Armstrong or not. ( Source )

153
armstrong number
import java. util. Scanner ;
public class Program
{
    public static void main(String[] args)
    {
        int num,a,numm;
        int arm=0;
        boolean count =true ;
        Scanner kb=new Scanner (System.in);
        num=kb. nextInt();
        numm =num;
        while (num>0 )
        {
            a=num %10;
            num=num/10;
            arm =arm+(a*a*a);
        }
        if(arm==numm)
        {System.out.println ("armstrong number" );
        }
        else 
        {System.out.println ("not an armstrong number ");
        }
        
        
    }
}

2. By Priyankaโ™ฅ๏ธ

Made by Priyankaโ™ฅ๏ธ. Java Armstrong checker program. ( Source )

Enter number
123121
Entered number is:123121
it is not armstrong number

import java.util.*;

public class Program
{
    public static void main(String[] args) {
    
    int num,n,r,sum=0;
    System.out.println("Enter number");
    Scanner sc=new Scanner(System.in);
    num=sc.nextInt();
    System.out.println("Entered number is:"+num);
    n=num;
    while(num!=0)
    {
        r=num%10;
        sum=sum+r*r*r;
        num=num/10;
        
    }
    if(n==sum)
    {
        System.out.println("it is armstrong number");
        
     }
    else 
    {
        System.out.println("it is not armstrong number");
        
    }
    
    
    }
}

3. By Ali Han Demir

Made by Ali Han Demir. ( Source )

371
Your number is Armstrong Number : 371
import java.util.Scanner;

public class Program

{
	public static void main(String[] args) {
	
	Scanner a = new Scanner(System.in);
	int number = a.nextInt();
	
	int ones,tens,hundred;
	
	ones = number%10;
	tens = number/10%10;
	hundred = number/10/10%10;
	
	if (number == ((ones*ones*ones)+(tens*tens*tens)+(hundred*hundred*hundred))){
	    System.out.println("Your number is Armstrong Number : "+number);
	}
	else 
	   System.out.println("Your number isnt Armstrong Number");
	}
}

4. By World Champion

Made by World Champion. Enter a number then enter the number of digits of that number to check if its armstrong. ( Source )

Armstrong Number Checker

1234
4

The entered number 1234 is Not a Armstrong number
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
    
    int n,num,digit,d,sum=0;
    
        Scanner s=new Scanner(System.in);
     //   Scanner s1=new Scanner(System.in);
    
    System.out.println("\nArmstrong Number Checker\n");
     
     n=s.nextInt();
     d=s.nextInt();
     
     num=n;
     
     while(n>0){
         
         digit=n%10;
         
         sum+=Math.pow(digit,d);
         
         n/=10;
         
     }
        
       if(num==sum){
           
           System.out.println("\nThe entered number "+num+" is a Armstrong Number");
       }else{
           
           System.out.println("\nThe entered number "+num+" is Not a Armstrong number");
           
       }
        
    }
}

5. By Andreas Schenk

Made by Andreas Schenk. Enter you input number in int number =. ( Source )

7777
7777 is not an Armstrong number
public class Program
{
	public static void main(String[] args) {
//////////////////////////////////////////

		//here you can enter a singel number
		int number = 7777; // max. 99999
		
		//OR here you can enter a range of numbers
		int lowerNumber = 0;
		int upperNumber = 0; // max. 99999

//////////////////////////////////////////
		
		//Variabeldeklaration
		int zif_5;
		int zif_4;
		int zif_3;
		int zif_2;
		int zif_1;
		
		double exp;
		int ergebnis;
		
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++
		//Berechnungen und Test fรผr eine einzelne Zahl
		if(number > 0 && number < 100000 && lowerNumber+upperNumber == 0)
		{
			//Aufschlรผsselung nach Ziffern
			zif_5 = number/10000;
			zif_4 = (number-zif_5*10000)/1000;
			zif_3 = (number-zif_5*10000-zif_4*1000)/100;
			zif_2 = (number-zif_5*10000-zif_4*1000-zif_3*100)/10;
			zif_1 =  number-zif_5*10000-zif_4*1000-zif_3*100-zif_2*10;
			
			//Anzahl der Stellen fรผr den Exponenten ermitteln
			exp = 5;
			if(zif_5 == 0)
			{
				exp = 4;
				if(zif_4 == 0)
				{
					exp = 3;
					if(zif_3 == 0)
					{
						exp = 2;
						if(zif_2 == 0)
						{
							exp = 1;
						}
					}
				}
			}
			
			//Quadrierung und Summierung
			ergebnis = (int)Math.pow((double)zif_1, exp) + 
								 (int)Math.pow((double)zif_2, exp) + 
								 (int)Math.pow((double)zif_3, exp) + 
								 (int)Math.pow((double)zif_4, exp) +
								 (int)Math.pow((double)zif_5, exp);
			
			//Auswertung und Ausgabe
			if(number == ergebnis)
			{
				System.out.println(number + " is an Armstrong number");
			}
			else
			{
				System.out.println(number + " is not an Armstrong number");
			}
		}
		else if(number >= 100000)
		{
			System.out.println("The number must be smaller than 100000.");
		}
		else if(number > 0 && lowerNumber+upperNumber > 0)
		{
			System.out.println("Do you want to check a single number or a range?");
				System.out.println("Please enter zero to the one you don't want to check.");
		}
		
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++
		//Berechnungen und Test fรผr einen Range
		if(upperNumber < 100000 && number == 0)
		{
			for(int i = lowerNumber;i <= upperNumber;i++)
				{
						//Aufschlรผsselung nach Ziffern
						zif_5 = i/10000;
						zif_4 = (i-zif_5*10000)/1000;
						zif_3 = (i-zif_5*10000-zif_4*1000)/100;
						zif_2 = (i-zif_5*10000-zif_4*1000-zif_3*100)/10;
						zif_1 =  i-zif_5*10000-zif_4*1000-zif_3*100-zif_2*10;
			
						//Anzahl der Stellen fรผr den Exponenten ermitteln
						exp = 5;
						if(zif_5 == 0)
						{
							exp = 4;
							if(zif_4 == 0)
							{
								exp = 3;
								if(zif_3 == 0)
								{
									exp = 2;
									if(zif_2 == 0)
									{
										exp = 1;
									}
								}
							}
						}
			
						//Quadrierung und Summierung
						ergebnis = (int)Math.pow((double)zif_1, exp) + 
											 (int)Math.pow((double)zif_2, exp) + 
											 (int)Math.pow((double)zif_3, exp) + 
											 (int)Math.pow((double)zif_4, exp) + 
											 (int)Math.pow((double)zif_5, exp);
			
						//Auswertung und Ausgabe
						if(i == ergebnis)
						{
								System.out.println(i + " is an Armstrong Number");
						}
				}
		}
		else if(number == 0)
		{
			System.out.println("Range to high!");
		}
	}
}

6. By World Champion

Another Armstrong checker program by World Champion which finds all the Armstrong numbers between two numbers. Enter the range in ‘ for(int i=100;i<=999;i++) ‘ ( Source )

Armstrong number in range are 

153
370
371
407
public class ArmstrongInRange
{
    public static void main(String[] args) {
        
        
        int n,digit,sum;
        
        //3 digit Armstrong numbers 
        
        System.out.println("\nArmstrong number in range are \n");
        
                  for(int i=100;i<=999;i++){
                  
                  sum=0;
            
                   n=i;
                   
                        while(n>0){
                            
                            digit=n%10;
                            
                                                  
                                                  
                                                sum+=Math.pow(digit,3);
                            
                          n/=10;
                            
                            
                        }
                        
                        if(sum==i){
                            
                            System.out.println(sum);
                        }
                        
                }
        
    }
}

7. By Nilesh

Made by Nilesh. ( Source )

370
The given input number 370 is a armstrong number
import java.util.Scanner;
class Armstrong_number
{
    public static void main(String[] args) 
    {
    
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int r = 0;
    int a = 0;
    int s = 0;
    r=n;
    while(r!=0)  
   {
       a=r%10;
       s=s+a*a*a;
       r=r/10; 
   } 
   if(s==n)
   System.out.println("The given input number " + n + " is a armstrong number");
   else
   System.out.println("The given input number " + n + " is not a armstrong number");
    }
}

8. By Rashi Chauhan

Made by Rashi Chauhan. ( Source )

Enter number to be checked
234
234 is not an Armstrong number
import java.util.*;
class Armstrong
{
    public static void main(String[] args) 
    {
        Scanner sc=new Scanner(System.in);
        int a,n,s=0;
        System.out.println("Enter number to be checked");
        n=sc.nextInt();
        int m=n;
        do
        {
      a=n%10;
      s=s+(a*a*a);
      n=n/10;
        }
        while(n!=0);
        if(s==m)
        System.out.println(m+" is an Armstrong number");
        else
        System.out.println(m+" is not an Armstrong number");
    }
}

9. By Sumit Programmer

Made by Sumit Programmer. ( Source )

134
not a Armstrong number=134
import java.util.Scanner;
public class ArmstrongNumber
{
/* ArmstrongNumber =153
          153=1*1*1+5*5*5+3*3*3
            =1+125+27
            =153
         370=3*3*3+7*7*7+0*0*0
            =27+343+0
            =370*/
    public static void main(String[] args) {
    Scanner obj=new Scanner(System.in);
        int a=obj.nextInt();
        int d=a;
        int sum=0,b,c=0;
        while(a>0){
            b=a%10;
            c=(b*b*b);
            a=a/10;
            sum=sum+c;
           }
           if(sum==d)
 System.out.print("its Armstrong number= "+d);
           else
System.out.println("not a Armstrong number="+d); 
    }
}

10. By Piyu

Made by Piyu. ( Source )

153
153 is an Armstrong number
import java.util.*;
public class Program
{
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int r,sum=0;
       int p=0;
       int a=n;
       while(a>0)
       {
       p++;
       a=a/10;
       }
       a=n;
       while(n>0) 
       {
           r=n%10;
           sum+=Math.pow(r,p);
           n=n/10;
       }
       if(sum==a)
       System.out.println(a+" is an Armstrong number");
       else
       System.out.println(a+" is not an Armstrong number");
    }
}

11. By Mradul Uttam

Made by Mradul Uttam. Java program to check for Armstrong number. ( Source )

Please enter a no. of three digit
334
It is not an armstrong no.
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       System.out.println("Please enter a no. of three digit");
        int no=sc.nextInt();
        int a=no/10;
        no%=10;
        int b=no/10;
        no%=10;
        int c=no/10;
        int ps=a*a*a+b*b*b+c*c*c;
        if(no==ps){
        System.out.println("It is an armstrong no.");}
        else {
            System.out.println("It is not an armstrong no.");
        }
    }
}

12. By Hosseinam

Made by Hosseinam. ( Source )

please enter your number to dedicate that is armstrong or not : 2324
not armstrong number
import java.util.Scanner;

public class Armstrong {
    public static void main(String[] args) {
        System.out.println("please enter your number to dedicate that is armstrong or not : ");
        Scanner scanner=new Scanner(System.in);
        System.out.println(armstrong(scanner.nextInt()));
    }
    private static String armstrong(int a){

        int t=a,x=0;
        while (t%10!=0){
            x+=Math.pow((t%10),3);
            t/=10;
        }
        return (x==a)?"armstrong number":"not armstrong number";
    }
}

13. By David Akhihiero

Made by David Akhihiero. ( Source )

371
371 is an Armstrong Number
import java.util.Scanner;
public class ArmstrongNumber
{
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in); 
      try{
      String number = sc.nextLine();
       int digitsCubeSum = 0;
       for(int i=0;i<number.length();i++){
        int digit = Integer.parseInt(String.valueOf(number.charAt(i)));
        digitsCubeSum+=(Math.pow((double)digit,3));
       }
       if(digitsCubeSum==Integer.parseInt(number))
       System.out.println(number+" is an Armstrong Number");
else 
    System.out.println(number+" is not an Armstrong Number");
       }
       catch(NumberFormatException e){
           System.out.println("Invalid Input");
       }
    }
}

14. By Amit Haldiya

Made by Amit Haldiya. Java Armstrong finder using recursion. ( Source )

22
number is no amstrong
import java.io.*;
import java.util.*;
public class Program
{
    public static void main(String[] args) {
      int rem=0,sum=0;
    Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=n;
        while(n!=0)
        {
            rem=n%10;
            sum+=rem*rem*rem;
            n/=10;
            
        }
        if(m==sum)
        {
            System.out.println("number is amstrong");
            
        }
        else
        {
            System.out.println("number is no amstrong");
        }
    }
}

15. By Prantik Sarkar

Made by Prantik Sarkar. Program to check for Armstrong numbers in a given range. ( Source )

Enter the limit: 1000
1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 
import java.util.Scanner;
public class ArmstrongNumbers
 {
	public static void main(String[] args)
 {
		int limit;
Scanner ip = new Scanner(System.in);
System.out.print("Enter the limit: ");
		limit = ip.nextInt();
		for (int i = 1; i <= limit; i++)
           {
			if (isArmstrong(i))
	System.out.print(i + ", ");
	      	}
		ip.close();
	}
	// check whether the number passed within this method is armstrong number or not
private static boolean isArmstrong(int num)
 {
		int temp = num;
		int len = findLength(num);
		int result = 0;
		while (num > 0)
 {
			int rem = num % 10;
result = (int)(result + Math.pow(rem, len));
			num = num / 10;
		}
		if (result == temp)
			return true;
		else
			return false;
      }
// to find the length of the number
	private static int findLength(int num)   
   {
		int len = 0;
		while (num > 0)
      {
			len++;
			num = num / 10;
		}
		return len;
	}
}

16. By Raphael Williams

Made by Raphael Williams. ( Source )

Enter a 3 digit number to find if its an Armstrong number:

370

Number:370 is an Armstrong number


import java.util.Scanner;

public class Armstrong{
public static void main(String[] args) {
        System.out.println("Enter a 3 digit number to find if                                   its an Armstrong number:");
        int number = new Scanner(System.in).nextInt();
        
        if(isArmStrong(number)){
        System.out.println("\nNumber:" + number + " is an Armstrong number");
        }
     else{
     System.out.println("\nNumber:" + number + " is NOT an Armstrong number");
     }
}

    private static boolean isArmStrong(int number){
    int result = 0;
    int orig = number;
    while(number != 0 ){
    int remainder = number%10;
    result = result + remainder * remainder * remainder;
    number = number/10;
    }
    
    if(orig == result){
    return true;
    }
    return false;
    }
}

17. By Pradheepviki

Made by Pradheepviki. ( Source )

407
not a armstrong number
import java.util.*;
public class Program
{
    public static boolean isArmstrong(int n)
    {
        int c=0,a=0;
        int temp=n;
        while(temp>0)
        {
            a=temp%10;
            c+=a*a*a;
            temp=temp/10;
        }
        return(c==n);
    }
    public static void main(String[] args) 
    {
        int m,i;
        Scanner sc=new Scanner(System.in);
        m=sc.nextInt();
        for(i=0;i<m;i++)
        {
            if(isArmstrong(i))
            {
                System.out.println("armstrong number is:"+i);
            }
            else
            {
                System.out.println("not a armstrong number");
            }
        }
    }
}

18. By PR

Made by PR. ( Source )

Armstrong numbers from 100 to 1000:153 370 371 407 

public class Armstrong
{
    public static void main(String[] args) 
     {
        int n, count = 0, a, b, c, sum = 0;
        System.out.print("Armstrong numbers from 100 to 1000:");
        for(int i = 100; i <= 1000; i++)
        {
            n = i;
            while(n > 0)
            {
                b = n % 10;
                sum = sum + (b * b * b);
                n = n / 10;
            }
            if(sum == i)
            {
                System.out.print(i+" ");
            }
            sum = 0;
        }
    }
}