public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the month (1-12):");
int month = input.nextInt();
System.out.print("Enter the day (1-31):");
int day = input.nextInt();
System.out.print("Enter the year (ex. 2014):");
int year = input.nextInt();
if (month == 1)
month = 13;
else if (month == 2)
month = 14;
int Zeller = day + ((26 * (month + 1))/10) + year +
(year/4) + (6 * (year/100)) + (year/400);
int dayofweek = (Zeller + 5) % 7 + 1;
if (dayofweek == 1)
System.out.print("Day of the week: Monday");
else if (dayofweek == 2)
System.out.print("Day of the week: Tuesday");
else if (dayofweek == 3)
System.out.print("Day of the week: Wednesday");
else if (dayofweek == 4)
System.out.print("Day of the week: Thursday");
else if (dayofweek == 5)
System.out.print("Day of the week: Friday");
else if (dayofweek == 6)
System.out.print("Day of the week: Saturday");
else if (dayofweek == 7)
System.out.print("Day of the week: Sunday");
}
코드는 1 월과 2 월의 날짜를 올바르게 계산하지 않습니다. 항상 하루나 이틀입니다.젤러의 합동 코드 오류
예 : Jan 1, 2010
을 입력하면 코드에 Day of the week: Friday
이 출력되지만 그 대신 Day of the week: Saturday
이 출력됩니다.
제 계산에서 오류를 찾을 수 없습니다.
내가 년/100',''무서워 년/400' 및 기타 정수 구분. –
여기서 어떻게해야합니까? 새로운 인터 사이거 야? – Michael
정수 나누기를 할 때 "계산을 점검했다"고 말할 때? 그 용어가 당신에게 아무런 의미가 없다면 그것은 아마도 당신의 버그의 근원 일 것입니다. – dimo414