import java.util.Scanner;
public class MenologyV2{
//判断闰年的方法
public static boolean isLeapYear(int year){
return (Year % 4 ==0 && year % 100 != 0 || year % 400 == 0);
}
// 判断此年此月有多少天
public static int getNumOfInMonth(int year,int month){
int numOfDays = 0;
switch(month){
case 2:
numOfDays = 28 + (isLeapYear(year) ? 1 : 0 );
break;
case 4:
case 6:
case 9:
case 11:
numOfDays = 30;
break;
default:
numOfDays = 31;
}
return numOfDays;
}
//计算过去的整年年之间共是多少天
public static int getTotalIntervalDays(int year ,int month){
int numOfIntervalDays = 0;
for (int tempYear = 1800; tempYear < year; tempYear++){
if(isLeapYear( year)){
numOfIntervalDays = numOfIntervalDays + 366;
}else{
numOfIntervalDays = numOfIntervalDays + 365;
}
int tempMonth = 1;
while (tempMonth < month) {
numOfIntervalDays=getNumOfInMonth( year, month);
tempMonth++;
}
return numOfIntervalDays;
}
//判断此月第一天为星期几
public static int getStartDay( int year,int month){
return (getTotalIntervalDays( year , month) + 3) % 7;
}
//main方法
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int year = input.nextInt();
int month = input.nextInt();
System.out.println(getStartDay(int year,int month));
}}问题在哪里?
System.out.println(getStartDay(int year,int month));//形参实参 没搞清楚啊,楼主
改成,这样,
System.out.println(getStartDay(year,month));其他的行 没有看了,
import java.util.Scanner;public class MenologyV2 { // 判断闰年的方法
public static boolean isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
} // 判断此年此月有多少天
public static int getNumOfInMonth(int year, int month) {
int numOfDays = 0;
switch (month) {
case 2:
numOfDays = 28 + (isLeapYear(year) ? 1 : 0);
break;
case 4:
case 6:
case 9:
case 11:
numOfDays = 30;
break;
default:
numOfDays = 31; }
return numOfDays;
} // 计算过去的整年年之间共是多少天
public static int getTotalIntervalDays(int year, int month) {
int numOfIntervalDays = 0;
for (int tempYear = 1800; tempYear < year; tempYear++) {
if (isLeapYear(year)) {
numOfIntervalDays = numOfIntervalDays + 366;
} else {
numOfIntervalDays = numOfIntervalDays + 365;
} int tempMonth = 1;
while (tempMonth < month) { numOfIntervalDays = getNumOfInMonth(year, month);
tempMonth++; } }
return numOfIntervalDays;
} // 判断此月第一天为星期几
public static int getStartDay(int year, int month) { return (getTotalIntervalDays(year, month) + 3) % 7;
} // main方法
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int year = input.nextInt();
int month = input.nextInt();
System.out.println(getStartDay(year, month));
}}
public class MenologyV2{
//判断闰年的方法
public static boolean isLeapYear(int year){
return (year % 4 ==0 && year % 100 != 0 || year % 400 == 0);
}
// 判断此年此月有多少天
public static int getNumOfInMonth(int year,int month){
int numOfDays = 0;
switch(month){
case 2:
numOfDays = 28 + (isLeapYear(year) ? 1 : 0 );
break;
case 4:
case 6:
case 9:
case 11:
numOfDays = 30;
break;
default:
numOfDays = 31;
}
return numOfDays;
}
//计算过去的整年年之间共是多少天
public static int getTotalIntervalDays(int year ,int month){
int numOfIntervalDays = 0;
for (int tempYear = 1800; tempYear < year; tempYear++){
if(isLeapYear(tempYear)){//此处的year应该为现在tempYear
numOfIntervalDays = numOfIntervalDays + 366;
}else{
numOfIntervalDays = numOfIntervalDays + 365;
}
}//此处少了一个大括号
int tempMonth = 1;
while (tempMonth < month) {
numOfIntervalDays=numOfIntervalDays+getNumOfInMonth(year,tempMonth);
//此处的month应该为tempMonth,并且numOfIntervalDays需要加上以前的值。
tempMonth++;
}
return numOfIntervalDays;
}
//判断此月第一天为星期几
public static int getStartDay( int year,int month){
return (getTotalIntervalDays( year , month)+3) % 7;
}
//main方法
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int year = input.nextInt();
int month = input.nextInt();
System.out.println(getStartDay(year,month));//此处的参数前面不能加int
}}
import java.util.Scanner;
public class MenologyV2{
//判断闰年的方法
public static boolean isLeapYear(int year){
return (year % 4 ==0 && year % 100 != 0 || year % 400 == 0);
}
// 判断此年此月有多少天
public static int getNumOfInMonth(int year,int month){
int numOfDays = 0;
switch(month){
case 2:
numOfDays = 28 + (isLeapYear(year) ? 1 : 0 );
break;
case 4:
case 6:
case 9:
case 11:
numOfDays = 30;
break;
default:
numOfDays = 31;
}
return numOfDays;
}
//计算1900年到输入日期共是多少天
public static int getTotalIntervalDays(int year ,int month){
int numOfIntervalDays = 0;
for (int tempYear = 1900; tempYear < year; tempYear++){
if(isLeapYear( tempYear)){
numOfIntervalDays = numOfIntervalDays + 366;
}
else{
numOfIntervalDays = numOfIntervalDays + 365;
}
}
int tempMonth = 1;
int m = month;
while (tempMonth < month) {
numOfIntervalDays+=getNumOfInMonth( year, --m);
tempMonth++;
}
return numOfIntervalDays;
}
//判断此月第一天为星期几
public static int getStartDay( int year,int month){
return (getTotalIntervalDays( year , month) % 7 + 1);
}
//main方法
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int year = input.nextInt();
int month = input.nextInt();
System.out.print(year + "-" + month + "-1" + " 星期");
System.out.println(getStartDay( year, month));
}}