java 夜的第七章—— 输出日历

import java.util.*;
public class HW7_1 {
public static void main(String[] args) {
int days = 0;
int dayofmonth = 0;
Scanner input = new Scanner(System.in);
System.out.print("请输入年份:");
int year = input.nextInt(); 
System.out.print("请输入月份:");
int month = input.nextInt(); 
for (int i = 1900; i < year; i++) {
if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0)) { //判断是不是闰年
days = days + 366;
} else {
days = days + 365; //否则平年
}
}
for (int nomonth = 1; nomonth <= month; nomonth++) { //1,3,5,7,8,10,12为大月31天
if (nomonth == 1 || nomonth == 3 || nomonth == 5 || nomonth == 7
|| nomonth == 8 || nomonth == 10 || nomonth == 12) {
dayofmonth = 31;
} else if (nomonth == 2) {
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
dayofmonth = 29; //闰年二月29天
} else {
dayofmonth = 28; //平年二月28天
}
} else {
dayofmonth = 30; //其余的月份都为30天
}
if (nomonth < month) {
days = days + dayofmonth;
}
}
System.out.println("一/t二/t三/t四/t五/t六/t日");
int temp = (days % 7); 
for (int p = 0; p < temp; p++) {
System.out.print("/t");
}
for (int w = 1; w <= dayofmonth; w++) {
System.out.print(w + "/t");
if ((days + w) % 7 == 0) {
System.out.println();
}
}
}
}
 

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值