Question #296314

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


Expert's answer



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!

LATEST TUTORIALS
APPROVED BY CLIENTS