给定某年日期及该年第一天是星期几然后显示该年的日历


package lyt;

import javax.swing.*;


public class Lyt5 {

 
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String year=JOptionPane.showInputDialog(null,"请输入年份:","梁燕婷",JOptionPane.QUESTION_MESSAGE);
  String weekend=JOptionPane.showInputDialog(null,"请输入改年第一天的星期数:","梁燕婷",JOptionPane.QUESTION_MESSAGE);
  int year1=Integer.parseInt(year);
  int weekend1=Integer.parseInt(weekend);
  String []mouth={"January","February","March","April","May","June","July","August","September","October","November","December"};
        int []days={31,28,31,30,31,30,31,31,30,31,30,31};
        String []weekend2={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
        if((year1@0==0)||(year1%4==0&&year10!=0))   //判断该年是否是闰年与否
         days[1]=29;
  for(int i=0;i<12;i++)  //显示12个月份的循环代码
        {
         System.out.print("                                    "+mouth[i]);
         System.out.println("  " + year1);
         for(int j=0;j<90;j++)
         {
          System.out.print("*");
          if(j==89)
           System.out.println("*");           
         }
         for(int n=0;n<7;n++)
         {          
          if(n==6)
           System.out.printf("s\n",weekend2[n]); 
          else
           System.out.printf("s",weekend2[n]);
         }
         for(int r=0;r
       System.out.print("          ");
         for(int m=1;m<=days[i];m++)
         {          
          System.out.printf("d", m);
          weekend1++;
          if(weekend1%7==0)
           System.out.println("");       
           }
         System.out.println("");
        }
 }
}

posted on 2012-12-07 23:55  木本  阅读(172)  评论(0编辑  收藏  举报

导航