java — 简单的日历
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java — 简单的日历相关的知识,希望对你有一定的参考价值。
import java.util.Calendar;
import java.util.Scanner;
class Demo {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("请输入年份:");
int year = scan.nextInt();
System.out.print("请输入月份:");
int month = scan.nextInt();
System.out.println("\n\n\t\t"+year + "年" + month + "月\n\n");
System.out.println("周日\t周一\t周二\t周三\t周四\t周五\t周六");
Calendar c = Calendar.getInstance();
c.set(year, month-1, 1);
int weekday = c.get(Calendar.DAY_OF_WEEK);
int maxDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
int temp = 0;
for (int i = 1; i < weekday; i++){
System.out.print("*\t");
temp++;
}
for (int i = 1; i <= maxDay; i++){
System.out.print(i + "\t");
temp++;
if (temp%7 == 0){
System.out.println();
}
}
}
}
以上是关于java — 简单的日历的主要内容,如果未能解决你的问题,请参考以下文章