Q:

Write a Java program to print out all Armstrong numbers between 1 to 600 using loop

0

Write a Java program to print out all Armstrong numbers between 1 to 600 using loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

public class JavaLoopExcercise
{
    public static void main(String[] args)
    {
        int digit1,  
            digit2,  
            digit3;  
 
    for(int number = 1; number <= 600; number++)
    {
            int temp = number;
        digit1 = temp % 10;
 
            temp = temp / 10;
            digit2 = temp % 10;
 
            temp = temp / 10;
            digit3 = temp % 10;
 
        if(digit1*digit1*digit1 + digit2*digit2*digit2 + digit3*digit3*digit3 == number)
            {
            System.out.println(number);
            }
    }
    }  
}

Result:

1

153

370

371

407

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a java program to count total number of note... >>
<< Write a Java program to enter the numbers till the...