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 :)
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 :)