java月历_Java月历

package com.pas.action;

import java.util.Date;

import java.util.Scanner;

public class Year {

/**

* @param args

*/

public static void main(String[] args) {

Scanner mysc = new Scanner(System.in);

while (true) {

int sum = 0;

int week = 0;

int year = 0;

int month = 0;

System.out.println("年份:");

year = mysc.nextInt();

System.out.println("月份:");

month = mysc.nextInt();

for (int i = 1990; i < year; i++) {

if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {

sum += 366;

} else {

sum += 365;

}

}

System.out.println(sum);

for (int i = 1; i < month; i++) {

if (i == 2) {

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {

sum += 29;

} else {

sum += 28;

}

} else {

if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8

|| i == 10 || i == 12) {

sum += 31;

} else {

sum += 30;

}

}

}

System.out.println(sum);

week = sum % 7;

System.out.print("日\t一\t二\t三\t四\t五\t六");

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

for (int i = 0; i <= week; i++) {

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

}

int tem = 0;

if(month==2)

{

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {

tem= 29;

} else {

tem= 28;

}

}

else if (month == 1 || month == 3 || month == 5 || month == 7

|| month == 8 || month == 10 || month == 12) {

tem = 31;

} else {

tem = 30;

}

for (int i = 1; i <= tem; i++) {

sum++;

if (i == 1 && sum % 7 == 0) {

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

}

if (sum % 7 == 6) {

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

} else {

System.out.print(i + "\t");

}

}

System.out.println("");

}

}

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值