Answer to Question #309168 in Java | JSP | JSF for Jones

Question #309168

. Write an application that displays all even numbers from 2 to 100 inclusive, and that starts a new line after every multiple of 20 (20, 40, 60, and 80). Save the file as EvenNums.java.


1
Expert's answer
2022-03-10T18:08:04-0500
public class EvenNums {

    public void printAllEvenNumbers(){
        for (int i = 2; i <= 100; i++){
            if(i == 20 || i == 40 || i == 60 || i == 80){
                System.out.println();
            }
            if(i % 2 == 0) {
                System.out.print(i + " ");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS