Java Date and Time Problem
https://www.hackerrank.com/challenges/java-date-and-time/problem
这道算法题使用Java 8的Date & Time API很容易解决了。
public class Solution {
private static String getDay(String day, String month, String year) {
int d = Integer.parseInt(day);
int m = Integer.parseInt(month);
int y = Integer.parseInt(year);
LocalDate date = LocalDate.of(y, m, d);
return date.getDayOfWeek().toString();
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String month = in.next();
String day = in.next();
String year = in.next();
System.out.println(getDay(day, month, year));
}
}
June 22, 2018 ∙
java