199k views
4 votes
How many times the word "Hello" will be printed on the screen

for(int i = 10; i <= 0; i++)
{
System.out.print("hello ");
}

O zero
O 10
O infinite
O 11

User Niklas R
by
8.2k points

1 Answer

2 votes

Final answer:

The loop condition in the provided code snippet immediately evaluates to false, thus the loop body will not execute and "Hello" will be printed zero times.

Step-by-step explanation:

The question asks how many times the word "Hello" will be printed on the screen given the code snippet:

for(int i = 10; i <= 0; i++) {
System.out.print("hello ");
}

The for loop in the question has an initialization part where the variable i is set to 10. The condition for the loop to continue running is i <= 0. Thus, since the initial value of i is 10 and does not satisfy the condition to enter the loop, the loop body will not execute. Therefore, the word "Hello" will be printed zero times.

User TheRealPapa
by
8.3k points