Last active
September 28, 2015 08:29
-
-
Save ucchyocean/7990108567995d1b102f to your computer and use it in GitHub Desktop.
Java SE 8 Silver 試験で出た、LocalDate関連の問題2問。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 問題1 | |
// 下記のコードを実行した時に、画面に表示される結果を、選択肢 A~D から一つ選べ。 | |
LocalDate date = LocalDate.of(2015, 9, 31); | |
date = date.plusDays(10); | |
System.out.println(date); | |
// A. 2015-10-10 | |
// B. 2015-10-11 | |
// C. 実行時にDateTimeExceptionが発生する | |
// D. コンパイルエラー | |
// 問題2 | |
// 下記のコードを実行した時に、画面に表示される結果を、選択肢 A~D から一つ選べ。 | |
LocalDate date = LocalDate.of(2015, 7, 31); | |
date = date.plusDays(31); | |
date = date.plusMonths(1); | |
System.out.println(date); | |
// A. 2015-10-01 | |
// B. 2015-09-30 | |
// C. 実行時にDateTimeExceptionが発生する | |
// D. コンパイルエラー |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
【正解】
問題1:C
LocalDate.ofに実際に存在しない日付を指定しようとすると、実行時に例外DateTimeExceptionが発生する。
問題2:B
date.plusDays(31); を実行すると、「2015-08-31」になるが、更にdate.plusMonths(1);を実行すると、次の月の最終日に設定されるので「2015-09-30」になる。