What is the output of the following?
14: int count = 0; 15: LocalDate date = LocalDate.of(2020, Month.JANUARY, 1); 16: while (date.getMonth() != Month.APRIL) 17: date = date.minusMonths(1); 18: count++; 19: System.out.println(count);
B.
Since there are not brackets around the while loop, only line 17 is in the loop body.
Line 18 gets executed once after the loop completes.
count will be 1 assuming the loop completes.
Subtracting a month from JANUARY results in DECEMBER.
Since the loop completes E is incorrect and Option B is the answer.
If the brackets were added as the indentation suggests, Option D would be the answer since we are counting months backwards.