Computer Science, asked by dwivedic8, 7 months ago

Write a program to input any number between 1 and 500 and check

it for Armstrong number and print the appropriate message. If sum of

cubes of each digit of the number is equal to the number itself, then the

number is called an Armstrong number.

For example: 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

Answers

Answered by Oreki
1

import java.util.Scanner;

public class ArmstrongNumber {

static boolean isArmstrong(int number) {

int digitCube = 0;

for (int temp = number; temp != 0; temp /= 10)

digitCube += Math.pow(temp % 10, 3);

return number = = digitCube;

}

public static void main(String[ ] args) {

System.out.print("Enter a number to be checked (1 to 500) - ");

int number = new Scanner(System.in).nextInt( );

System.out.printf("It is%sa Armstrong number.", isArmstrong(number) ? " " : " not ");

}

}

Similar questions