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

Question #296316

Display even numbers from 5 to 5000 using the while loop ,for loop and do while loop


1
Expert's answer
2022-02-11T00:27:33-0500
public class Main {
    public static void main(String[] args) {
        for (int i = 5; i < 5001; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
        int i = 5;
        while (i < 5001) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
            i++;
        }
        i = 5;
        do {
            if (i % 2 == 0) {
                System.out.println(i);
            }
            i++;
        } while (i < 5001);
    }
}

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