感谢大神作者: zhangwenjin 时间: 2016-6-25 22:50
import java.util.Scanner;
class wan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入一个年份");
int year = sc.nextInt();
System.out.println("输入一个月份");
int month = sc.nextInt();
int yearday = 0 ;
if (year / 400 ==0) {
yearday = 366;
System.out.println(year+"是闰年");
}else if (year % 100 != 0 && year % 4 == 0) {
yearday = 366;
System.out.println(year+"是闰年");
}else {
yearday = 365;
System.out.println(year+"是平年");
}
//获取输入年份到1900年的总天数
int z = 0;
for (int a = 1900;a < year ;a++ ) {
if (a / 400 ==0) {
z += 366;
}else if (a % 100 != 0 && a % 4 == 0) {
z += 366;
}else {
z += 365;
}
}
int y = 0;
for (int i = 1;i < month ;i++ ) {
y += getDay(i , year);
}
System.out.println("一\t二\t三\t四\t五\t六\t日");
int week = (z + y) % 7 + 1;
for (int x = 1 ;x <= week ;x++ ) {
if (week ==7) {
break;
}
System.out.print("\t");
}
for (int x = 1;x <= getDay(month , year) ; x++ ) {
System.out.print(x+"\t");
if ((x + week)%7==0) {
System.out.println();
}
}
}
//获取输入月份的天数
public static int getDay(int a , int b){
int day = 0;
switch (a) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day =31;
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
case 2:
if ( b / 400 ==0) {
day = 29;
}else if (b % 100 != 0 && b % 4 == 0) {
day = 29;
}else {
day = 28;
}
break;
}
return day;
}
} 作者: a820290471 时间: 2016-6-25 22:52
上面的大神们真是6的飞起作者: 气势如虹 时间: 2016-6-25 23:01
我好想偶遇了大神呀,双击评论666作者: 貂裘换酒 时间: 2016-6-30 09:24