import java.util.Scanner;
public class rili {    
public static void main(String[] args)     {        
Scanner input=new Scanner(System.in);     
    int year;   
    int month;        
    int days=0;     
    int sum=0;    
     int sum1=0;    
     int sum2=0;    
     String s;        
       do        
{             //输入年份和月份并判断是否合法;           
    do          
    {           
      System.out.println("请输入年份:");
              year=input.nextInt();      
         }        
  while(year<1900);     
        do          
     {           
    System.out.println("请输入月份:");            
   month=input.nextInt();         
      }            
while(month<=0||month>12);      
       //求这个月的第一天是这一年的第几天;        
     for(int i=1;i<=month;i++)          
   {                 //判断每月的天数;              
   switch(i)                
  {               
      case 2:             
        if(year%4==0&&year%100!=0||year%400==0)           
          {                       
      days=29;                 
      }                   
    else                   
    {                   
        days=28;              
       }                  
     break;                
case 4:                
case 6:              
case 9:               
case 11:                   
  days=30;                    
break;                
default:                    
days=31;                    
break;               
  }            
     if(i<month)               
  {               
  sum1+=days;              
   }        
}        
    //求从1900.01.01开始过到咯第几天;   
          for(int j=1900;j<year;j++)          
   {                            
      if(j%4==0&&j%100!=0||j%400==0)         
          {                
         sum2+=366;       
            }           
      else              
     {                  
     sum2+=365;           
         }      
       }           
  sum=sum1+sum2;      
   //判断这一年的这个月的第一天是星期几;  
       int e=(sum+1)%7;        
System.out.println("日\t一\t二\t三\t四\t五\t六");     
        for(int i=1;i<=e;i++)           
    {             
  System.out.print("\t");     
        }           
  for(int a=1;a<=days;a++)    
         {         
        System.out.print(a+"\t");      
           if((sum+a)%7==6)           
      {                
    System.out.println();        
         }         
    }           
  sum1=0;        
  sum2=0;           
  sum=0;           
  System.out.println("\n");      
       do            
  {            
    System.out.println("是否继续查看:(是/否)");   
            s=input.next();        
     }          
   while(!(s.equals("是")||s.equals("否")));    
     }
while(s.equals("是"));    
}
}