import java.util.Scanner;
class RiLi
{
public static void main(String[] args)
{
//输入要查询的年份和月份
Scanner in = new Scanner(System.in);
int statue=1;
while(statue==1){
System.out.println("请输入你要查看的年份!");
int findYear = in.nextInt();
System.out.println("请输入你要查看的月份!");
int findMonth = in.nextInt();
//万年历起始时间
String s = "1900年1月1日星期一";
//计算出查询年的第一天是星期几
int i = 0,allDay = 0;
for(i=1900;i<findYear;i++){
if(i%4==0 && i%100!=0 || i%400==0){
allDay += 366;
}
else{
allDay += 365;
}
}
//计算查询月的第一天是星期几
//判断该年为平年还是闰年
int weekday = 0;
int yearType = 0;//0为平年 365天 2月28天,1为闰年 366天 2月29天
int count = 0;
if(findYear%4==0 && findYear%100!=0 || findYear%400==0){
switch(findMonth){
case 2:
count = 31;
break;
case 4:
case 6:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 -2) + 29;
break;
case 9:
case 11:
count = 31 * (findMonth / 2 +1) + 30 * (findMonth / 2 - 2) + 29;
break;
case 1:
count = 0;
break;
case 3:
case 5:
case 7:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 1) + 29;
break;
case 8:
case 10:
case 12:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 2) + 29;
break;
}
}
else{
switch(findMonth){
case 2:
count = 31;
break;
case 4:
case 6:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 -2) + 28;
break;
case 9:
case 11:
count = 31 * (findMonth / 2 +1) + 30 * (findMonth / 2 - 2) + 28;
break;
case 1:
count = 0;
break;
case 3:
case 5:
case 7:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 1) + 28;
break;
case 8:
case 10:
case 12:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 2) + 28;
break;
}
}
weekday = (count + allDay) % 7 + 1;
System.out.println(weekday);
System.out.print("日\t");
System.out.print("一\t");
System.out.print("二\t");
System.out.print("三\t");
System.out.print("四\t");
System.out.print("五\t");
System.out.print("六\t");
System.out.println();
int flag=0;
if(findMonth == 1 || findMonth == 3 || findMonth == 5 || findMonth == 7 || findMonth == 8 || findMonth == 10 || findMonth == 12){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=31;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(findMonth == 4 || findMonth == 6 || findMonth == 9 || findMonth == 11){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=30;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(yearType == 1 && findMonth ==2){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=29;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(yearType == 0 && findMonth ==2){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=28;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
System.out.println();
System.out.println("退出输入0,继续输入1");
statue = in.nextInt();
}
}
class RiLi
{
public static void main(String[] args)
{
//输入要查询的年份和月份
Scanner in = new Scanner(System.in);
int statue=1;
while(statue==1){
System.out.println("请输入你要查看的年份!");
int findYear = in.nextInt();
System.out.println("请输入你要查看的月份!");
int findMonth = in.nextInt();
//万年历起始时间
String s = "1900年1月1日星期一";
//计算出查询年的第一天是星期几
int i = 0,allDay = 0;
for(i=1900;i<findYear;i++){
if(i%4==0 && i%100!=0 || i%400==0){
allDay += 366;
}
else{
allDay += 365;
}
}
//计算查询月的第一天是星期几
//判断该年为平年还是闰年
int weekday = 0;
int yearType = 0;//0为平年 365天 2月28天,1为闰年 366天 2月29天
int count = 0;
if(findYear%4==0 && findYear%100!=0 || findYear%400==0){
switch(findMonth){
case 2:
count = 31;
break;
case 4:
case 6:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 -2) + 29;
break;
case 9:
case 11:
count = 31 * (findMonth / 2 +1) + 30 * (findMonth / 2 - 2) + 29;
break;
case 1:
count = 0;
break;
case 3:
case 5:
case 7:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 1) + 29;
break;
case 8:
case 10:
case 12:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 2) + 29;
break;
}
}
else{
switch(findMonth){
case 2:
count = 31;
break;
case 4:
case 6:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 -2) + 28;
break;
case 9:
case 11:
count = 31 * (findMonth / 2 +1) + 30 * (findMonth / 2 - 2) + 28;
break;
case 1:
count = 0;
break;
case 3:
case 5:
case 7:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 1) + 28;
break;
case 8:
case 10:
case 12:
count = 31 * (findMonth / 2) + 30 * (findMonth / 2 - 2) + 28;
break;
}
}
weekday = (count + allDay) % 7 + 1;
System.out.println(weekday);
System.out.print("日\t");
System.out.print("一\t");
System.out.print("二\t");
System.out.print("三\t");
System.out.print("四\t");
System.out.print("五\t");
System.out.print("六\t");
System.out.println();
int flag=0;
if(findMonth == 1 || findMonth == 3 || findMonth == 5 || findMonth == 7 || findMonth == 8 || findMonth == 10 || findMonth == 12){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=31;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(findMonth == 4 || findMonth == 6 || findMonth == 9 || findMonth == 11){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=30;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(yearType == 1 && findMonth ==2){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=29;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
if(yearType == 0 && findMonth ==2){
for(int k=1;k<=weekday;k++){
System.out.print("\t");
flag++;
}
for(int j=1;j<=28;j++){
if(flag%7==0){
System.out.println();
}
System.out.print(j+"\t");
flag++;
}
flag=0;
}
System.out.println();
System.out.println("退出输入0,继续输入1");
statue = in.nextInt();
}
}
- }