我正在尝试解决这个涉及一些计算的非常基本的问题。但是我的计算得到了不同的结果。(它返回 6,使用示例中给出的输入,它应该返回 1(星期日)。
这是问题:
这就是我正在尝试的:
Scanner sc = new Scanner(System.in);
System.out.println("Enter year: (e.g., 2012): ");
int year = sc.nextInt();
System.out.println("Enter month: 1-12: ");
int month = sc.nextInt();
System.out.println("Enter the day of the month: 1-31: ");
int day = sc.nextInt();
//calculate the day using the forumla
int k = year % 100;
int j = year / 100;
int weekDay = (int)((day + ( 26 * (month + 1))/10.0 + k + k/4.0 + j/4.0 + (5*j)) % 7);
