Java OCA OCP Practice Question 785

Question

How many lines does this program print?

import java.time.*; 
public class Main { 
  public static void main(String... nums) { 
     LocalTime time = LocalTime.of(1, 11); 
     while (time.getHour() < 1) { 
        time.plusHours(1); /* www. ja v  a  2 s .  c om*/
        System.out.println("in loop"); 
     } 
  } 
} 
  • A. None
  • B. One
  • C. Two
  • D. This is an infinite loop.
  • E. The code does not compile.


A.

Note

A while loop checks the condition before executing.

Since the hour is not less than one, the loop never enters, and Option A is correct.




PreviousNext

Related