当前位置: 主页 > 12博手机版app >

用java设计一个2016年7月的日历

来自:原创| 发布时间:2020-05-18 01:16 | 作者:admin

  你的Java日历依次我帮你改好了,你看看吧.(修改的中央见注释)

  import java.util.*;

  public class JavaApplication17{

  public static void main(String[] args) {

  ClendarBean cb = new ClendarBean();

  cb.setMonth(2016);

  cb.setMonth(11);

  String a[] = cb.getCalendar();

  char str[] ="日一二三四五六".toCharArray();

  for(char c:str){

  System.out.printf("%7c",c);//这里改一e69da5e6ba90e79fa5e9819331333361323639下"%3c"改成"%7c"

  }

  System.out.println();//这里加一句换行

  for(int i=0;i

  System.out.printf("%3s",a[i]);//这里"%3c"改成"%3s"并移到这里

  if((i+1)%7==0){//这里i%7==0改成(i+1)%7==0

  System.out.println();

  }

  }

  }

  }

  class ClendarBean{

  int year = 0;

  int month = 0;

  public void setYear(int year){

  this.year = year;

  }

  public void setMonth(int month){

  this.month = month;

  }

  public String [] getCalendar(){

  String a[] = new String[45];

  Calendar calendar = Calendar.getInstance();

  calendar.set(year,month-1,1);

  int weekDay = calendar.get(Calendar.DAY_OF_WEEK)-1;

  int day = 0;

  if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){

  day = 31;

  }

  if(month==4 || month==6 || month== 9 || month==11){

  day = 30;

  }

  if(month==2){

  if(year%4==0&year%100 !=0 || year%400==0){

  day = 29;

  }

  else day = 28;

  }

  for(int i=0;i

  a[i] ="";

  }

  for(int i=weekDay+1,n=1;i

  a[i] = String.valueOf(n);

  n++;

  }

  for(int i=weekDay+day+1;i

  a[i] = "";

  }

  return a;

  }

  }

  运转结果