兰州大学java日历程序两行输出
更新时间:2023-08-10 08:01:01 阅读量: 工程科技 文档下载
- java编写日历程序推荐度:
- 相关推荐
兰州大学 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();
正在阅读:
兰州大学java日历程序两行输出08-10
中秋节的习俗有哪些优秀7篇03-27
Pre---Test07-10
结绳方法03-17
抗日战争胜利76周年的启示【优秀4篇】03-26
百家讲坛长征观后感04-01
《送友人》李白09-05
精益管理思考-精益生产06-06