Java Programs

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 ?

[java]

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");
        }

    }
}

[/java]

Output :

Enter a Number 371
ArmStrong Number
Enter a Number 180
Not an ArmStrong Number

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment