- 2
What coding i use for armstrong
plzz tell me
2 Answers
+ 9
Please show your attempts when asking for help, many thanks.
0
/*
you can copy and paste in your IDE
then run
you can also change variable 'number' to check if other numbers is Armstrong or no
*/
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.");
}
}