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

Question #296314

display multiples of 5 to 5000 using the while loop,for loop and do while loop


1
Expert's answer
2022-02-11T00:45:20-0500


class App {


	public static void main(String[] args) {


		// for loop
		System.out.println("for loop:");
		for (int i = 0; i <= 5000; i++) {
			if (i % 5 == 0) {
				System.out.println(i);
			}
		}
		// while loop
		System.out.println("\n\nwhile loop:");
		int counter = 0;
		while (counter <= 5000) {
			if (counter % 5 == 0) {
				System.out.println(counter);
			}
			counter++;
		}
		// do while loop
		System.out.println("\n\ndo while loop:");
		counter = 0;
		do {
			if (counter % 5 == 0) {
				System.out.println(counter);
			}
			counter++;
		} while (counter <= 5000);


	}
}

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