Showing posts with label Java Programs for Armstrong number. Show all posts
Showing posts with label Java Programs for Armstrong number. Show all posts

Java Program to Check the Armstrong numbers | JAVA POINT Numbers

Java Program to Check the Armstrong numbers 



Armstrong number in Java
Armstrong number



Armstrong number

A number will be called Armstrong if the sum of cubes of each digits is equal to the original number.


Program


import java.util.Scanner;

public class Armstrong

{

    public static void main(String args[])

    {

        Scanner ob=new Scanner(System.in);

        System.out.println("Enter the number to be checked.");

        int num=ob.nextInt();

        int a,i,sum=0;

        i=num;


        while(num!=0) 

        {

            a=num%10;

            sum=sum+a*a*a;

            num=num/10;

          }

          if(sum==i)

              System.out.println(i+" is an Armstrong Number.");

          else

              System.out.println(i+" is not a Armstrong Number.");

    }

}


/*

Output :


Enter the number to be checked : 153

153 is an Armstrong Number.

(Workings 153 = 1*1*1 + 5*5*5 + 3*3*3)

*/


Also read :