We are uploading our contents, please refresh app.
Java Premium

Write a program in java to input a number and check the number is an armstrong or not.

What is Armstrong Number ?

In an Armstrong Number, the sum of power of individual digits is equal to number itself.

In other words the following equation will hold true

xy..z = xn + yn+.....+ zn

n is number of digits in number

For example this is a 3 digit Armstrong number

370 = 33 + 73 + 03
    = 27 + 343 + 0
    = 370

Examples of Armstrong Numbers

0, 1, 4, 5, 9, 153, 371, 407, 8208, etc.

Program:
import java.util.*;
class Armstrong
{
public static void main(String args[])
{
int n,s=0,r,t;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to check its an armstrong or not:");
n=sc.nextInt();
t=n;
while(n!=0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(t==s)
{
System.out.println("Entered number is an armstrong");
}
else
System.out.println("Entered number is not an armstrong");
}
}

Output:
Enter the number to check its an armstrong or not:
123
Entered number is not an armstrong

Enter the number to check its an armstrong or not:
153
Entered number is an armstrong

Online user

Download our android app Download App Submit your query
x

Get Updates On

Java & Premium Programs

Java Solved & Questions

Java Coding easy to use

Proper Coding

Straight Into Your INBOX!

We are going to send you our resources for free. To collect your copy at first, join our mailing list. We are promising not to bother you by sending useless information. So don't miss any updates, stay connected!