PROGRAM : ARMSTRONG NUMBER
SYNTAX :
import java.io.*;
class armstrong
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;int n1;
System.out.println("Enter a Number");
n=Integer.parseInt(br.readLine());
n1=n;int d=0,sum=0;
while(n!=0)
{
d=n%10;
sum+=Math.pow(d,3);
n=n/10;
}
if(sum==n1)
System.out.println("The Number is ARMSTRONG");
else
System.out.println("NO THE NUMBER IS NOT ARMSTRONG");
}
}
Armstrong Number in Java. Armstrong Number in Java: Armstrong number is anumber that is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.
SYNTAX :
import java.io.*;
class armstrong
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;int n1;
System.out.println("Enter a Number");
n=Integer.parseInt(br.readLine());
n1=n;int d=0,sum=0;
while(n!=0)
{
d=n%10;
sum+=Math.pow(d,3);
n=n/10;
}
if(sum==n1)
System.out.println("The Number is ARMSTRONG");
else
System.out.println("NO THE NUMBER IS NOT ARMSTRONG");
}
}
Comments
Post a Comment