Saturday , August 19 2017
Home / java programs / Java Program To find A Number is ArmStrong or Not ?

Java Program To find A Number is ArmStrong or Not ?

Here we are going to write a program to check a number is ArmStrong or not ?

Number is ArmStrong or not ?


import java.util.Scanner;

public class ArmStrongNumber {

    public static void main(String a[]) {

        int remainder, dividor, sum = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a Number");
        int input = sc.nextInt();
        int temp = input;

        while (input > 0) {
            remainder = input % 10;
            input = input / 10;
            sum = sum + (remainder * remainder * remainder);
        }
        if (sum == temp) {
            System.out.println("ArmStrong Number");
        } else {
            System.out.println("Not an ArmStrong Number");
        }

    }
}

Output :

Enter a Number 371
ArmStrong Number

Enter a Number 180
Not an ArmStrong Number

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

Java program to find sum of digits

In this Java programming tutorials, I am going to show you how to calculate sum …

Leave a Reply

Your email address will not be published. Required fields are marked *