KnowledgeBoat Logo
|

Computer Applications

How many times will the following code print "Hello"?

for (int i = 1; i <= 5; i++);
{
    System.out.println("Hello");
}
  1. 0
  2. 1
  3. 5
  4. 4

Java Iterative Stmts

10 Likes

Answer

1

Reason — The for loop has a semicolon ; at the end. Thus, it becomes an empty loop and the program just waits till the loop finishes. Then the program executes the next statement System.out.println("Hello"); and prints Hello on the output screen.

Answered By

5 Likes


Related Questions