本文主要是介绍java笔记001之 迷你版万年历,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
public class HellowWorldClass {
privatestatic Scannera;
privatestatic Scannerb;
public static void main(String[] args) {
// TODO Auto-generated method stub
a = new Scanner(System.in);
int year = a.nextInt();
System.out.println("请输入年份为:" +year);
b = new Scanner(System.in);
int month = b.nextInt();
System.out.println("请输入月份:"+month);
//title
System.out.println(" <<<<<<<<<<<<<<<<迷你版 万年历>>>>>>>>>> ");
System.out.println(" "+year+"年"+month+"月");
String title[] = {"日","一","二","三","四","五","六"};
for(inti=0;i<=6;i++){
System.out.print(title[i] +"\t");
}
System.out.print("\n");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR,year);
cal.set(Calendar.MONDAY,month);
cal.set(Calendar.DATE, 1);
//用来获取当前的日期,是星期几
int weekday = cal.get(Calendar.DAY_OF_WEEK);
for(inti= 1;i<= weekday-1;i++){
System.out.print("\t");
}
int maxdate = cal.getActualMaximum(Calendar.DATE);//获取最大的天数
for(inti= 1;i<= maxdate;i++){
System.out.print(i +"\t");
if((i+weekday-1)%7 ==0){
System.out.print("\n");
}
}
}
}
这篇关于java笔记001之 迷你版万年历的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!