125k views
3 votes
How many times will the following for loop be executed?

for (int count = 10; count <= 21; count++)
System.out.println("Java is great!!!");
O 1
O 0
O 10
O 11

User DSoldo
by
7.4k points

1 Answer

3 votes

Final answer:

The for loop in the question will be executed 12 times. It starts at 10 and includes the count when it is equal to 21.

Step-by-step explanation:

The for loop you've provided will execute each time the variable count increments by 1, starting at 10 and continuing as long as count is less than or equal to 21. Specifically, it will execute for count at 10, 11, 12, ..., up to and including 21. To find out how many times the loop will execute, we simply subtract the starting value (10) from the ending value (21) and add 1 (since we're including both the start and end values in the count).

21 - 10 = 11

Therefore, 11 + 1 = 12, and the loop will execute 12 times.

User Maksadbek
by
8.1k points