Question #296316

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


Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS