What is the result of the following?
import java.time.*; import java.time.format.*; ? public class Main { public static void main(String[] args) { LocalDate newYears = LocalDate.of(2020, 1, 1); Period period = Period.ofDays(1); DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-dd-yyyy"); System.out.print(format.format(newYears.minus(period))); } //w w w . java 2 s. c o m }
B.
The code starts by correctly creating a date representing January 1, 2020, and a period representing one day.
It then explicitly defines the format as month followed by day followed by year.
The code subtracts a day, giving us the formatted version of December 31, 2019.