任何人都可以告诉我我的代码有什么问题吗?我的输出结果不正确。干杯
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] days={"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
int month = in.nextInt();
int day = in.nextInt();
int year = in.nextInt();
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, day);
int day_of_week = c.get(Calendar.DAY_OF_WEEK)-1;
System.out.println(days[day_of_week]);
}
答案 0 :(得分:5)
阅读文档,然后转到
c.set(Calendar.MONTH, month -1);
因为它接受基于零的索引