兰州大学java日历程序两行输出

更新时间:2023-08-10 08:01:01 阅读量: 工程科技 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

兰州大学 java日历 程序两行输出

import java.util.*;

import java.io.*;

class cal{

private int year;

public cal(){year=1;};

public void setyear(int year){

this.year=year;

}

public int getyear(){

return year;

}

public void show(){

GregorianCalendar[] d=new GregorianCalendar[12];

int i;

for(i=0;i<12;i++){

d[i]=new GregorianCalendar();

}

for(i=0;i<12;i++){

d[i].set(Calendar.YEAR,year);

d[i].set(Calendar.MONTH,i);

d[i].set(Calendar.DAY_OF_MONTH,1);

}

for(i=0;i<12;i=i+2){

System.out.print("\n");

int month=d[i].get(Calendar.MONTH);

int month2=d[i+1].get(Calendar.MONTH);

int weekday=d[i].get(Calendar.DAY_OF_WEEK);

int weekday2=d[i+1].get(Calendar.DAY_OF_WEEK);

System.out.print(month+1+"月

System.out.print(month2+1+"月\n");

System.out.println(" 日 一 二 三 四 五

六");

int day,day2;

do

{

for(int k=Calendar.SUNDAY;k<weekday;k++)

System.out.print(" ");

if(d[i].get(Calendar.MONTH)!=month)

System.out.print("

else

{ *"); 六"+" * 日 一 *"); 二 三 四五

兰州大学 java日历 程序两行输出

while(weekday!=Calendar.SATURDAY){

day=d[i].get(Calendar.DAY_OF_MONTH);

if(d[i].get(Calendar.MONTH)!=month)

System.out.print(" ");

else System.out.printf("%3d ",day);

d[i].add(Calendar.DAY_OF_MONTH,1);

weekday=d[i].get(Calendar.DAY_OF_WEEK);

}

day=d[i].get(Calendar.DAY_OF_MONTH);

if(d[i].get(Calendar.MONTH)!=month)

System.out.print(" ");

else System.out.printf("%3d ",day);

d[i].add(Calendar.DAY_OF_MONTH,1);

weekday=d[i].get(Calendar.DAY_OF_WEEK);

System.out.print("*");

}

//////////////////////

if(d[i+1].get(Calendar.MONTH)!=month2)

System.out.print("\n");

else

{

for(int j=Calendar.SUNDAY;j<weekday2;j++)

System.out.print(" ");

while(weekday2!=Calendar.SATURDAY){

day2=d[i+1].get(Calendar.DAY_OF_MONTH);

if(d[i+1].get(Calendar.MONTH)!=month2)

System.out.print(" ");

else System.out.printf("%3d ",day2);

d[i+1].add(Calendar.DAY_OF_MONTH,1);

weekday2=d[i+1].get(Calendar.DAY_OF_WEEK);

}

day2=d[i+1].get(Calendar.DAY_OF_MONTH);

if(d[i+1].get(Calendar.MONTH)!=month2)

System.out.print(" ");

else System.out.printf("%3d ",day2);

d[i+1].add(Calendar.DAY_OF_MONTH,1);

weekday2=d[i+1].get(Calendar.DAY_OF_WEEK);

System.out.println("");

}

}

while(!(d[i].get(Calendar.MONTH)!=month&&d[i+1].get(Calendar.MONTH)!=month2)); }

}

兰州大学 java日历 程序两行输出

}

public class calendarTest {

public static void main(String[] args) { cal a=new cal();

}

} System.out.println("请输入年份:"); Scanner s=new Scanner(System.in); int year=s.nextInt(); a.setyear(year); a.show();

本文来源:https://www.bwwdw.com/article/3glj.html

Top