Computer Science, asked by nehabisht20, 7 months ago

WAp to accept a number and check whether the number is armstrong or not.​

Answers

Answered by ashi1532
1

Explanation:

______________________________________

Check Armstrong number for n digits

______________________________________

public class Armstrong {

public static void main(String[] args) {

int number = 1634, originalNumber, remainder, result = 0, n = 0;

originalNumber = number;

for (;originalNumber != 0; originalNumber /= 10, ++n);

originalNumber = number;

for (;originalNumber != 0; originalNumber /= 10)

{

remainder = originalNumber % 10;

result += Math.pow(remainder, n);

}

if(result == number)

System.out.println(number + " is an Armstrong number.");

else

System.out.println(number + " is not an Armstrong number.");

}

}

______________________________________

2nd program

Check Armstrong Number for 3 digit number

______________________________________

public class Armstrong {

public static void main(String[] args) {

int number = 371, originalNumber, remainder, result = 0;

originalNumber = number;

while (originalNumber != 0)

{

remainder = originalNumber % 10;

result += Math.pow(remainder, 3);

originalNumber /= 10;

}

if(result == number)

System.out.println(number + " is an Armstrong number.");

else

System.out.println(number + " is not an Armstrong number.");

}

}

hope it helps

mark brainlist

Answered by DumAssAmi
1

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

Similar questions