Can You Write A Java Program To Check Whether The Given Number Is An Amstrong Number Or Not?

4

4 Answers

Ellie Hoe Profile
Ellie Hoe answered
An Armstrong number is an integer whose sum of the cubes of each digits is same to the original number. Such as 371:
3^3+7^3+1^3=371

Following is the java code to check whether the given number is Armstrong or not

import java.io.Buffered Reader; //don't leave the gap
import java.io.IO Exception;//don't leave the gap
import java.io.Input StreamReader; //don't leave the gap

public class ArmstrongNumber
{

public static void main ( String[] a )
{
int a , value = 0 , c ,b = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

c = value;
System.out.print("Enter Number: ");
try
{
String str = br.readLine();
c = new Integer(str).intValue();
while (c != 0)
{
a = c % 10;
b = (a *a  a) + b;
c = c / 10;
}
if ( b == value )
System.out.print("given number is Armstrong number");
else
System.out.print("given number is not Armstrong number");

} catch (IOException e)
{
System.out.println(e);
}

}
}

Hope the above code will help you
Enjoy blurting :)
brijbihari rajouriya Profile
Import  java.util.Scanner;
class Num
{
public static void main(String args[])
{
int I,,j,sum,n;
Scanner in=new Scanner(System.in);
System.out.println("Enter number:");
n=in.nextInt();
while(n>0)
{
I=n%10;
sum=sum+I*I*I;
n=n/10;
}
if(sum==n)
System.out.println("number is amstrong");
else
System.out.println("number is not amstrong");
}
}
Anonymous Profile
Anonymous answered
No
Anonymous Profile
Anonymous answered
Take input from user in integer and show the prime number

Answer Question

Anonymous