Armstrong Number.
Program to check whether a given number is Armstrong number or not.
An Armstrong number of three digits is an integer such that he sum of the cubes of its digits is equal to the number itselt for example, 371 is an Armstrong number since
(3*3*3)+(7*7*7)+(1*1*1)=371
SOURCE CODE
import java.io.*;
public class Armstrong
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter a number :");
int a=Integer.parseInt(br.readLine());
int rem,arm=0,n;
n=a;
while(n>0)
{
rem=n%10;
arm=arm+(int)Math.pow(rem,3);
n=n/10;
}
if(arm==a)
{
System.out.println("Yes, It is a Armstrong No.");
}
else
{
System.out.println("No, It is not a Armstrong No.");
}
}
}
OUTPUT
If you have any question then leave a comment below I will do my best to answer that question
Comments
Post a Comment