赞
踩
- package 万年历;
- //传说中的万年历;
- import java.util.Scanner;
-
- public class A {
-
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- System.out.println("请输入你要查询的年");
- int year=in.nextInt();
- System.out.println("请输入你要查询的月");
- int month=in.nextInt();
- if(year%100!=0&&year%4==0||year%400==0){
- System.out.println("这年有366天");
- }else{
- System.out.println("这年有365天");
- }
- int md=31;
- switch(month){
- case 1:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 2:
-
- if(year%100!=0&&year%4==0||year%400==0){
- System.out.println("这个月有29天");
- md=29;
- }else{
- System.out.println("这个月有28天");
- md=28;
- }
- break;
- case 3:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 4:
- System.out.println("这个月有30天");
- md=30;
- break;
- case 5:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 6:
- System.out.println("这个月有30天");
- md=30;
- break;
- case 7:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 8:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 9:
- System.out.println("这个月有30天");
- md=30;
- break;
- case 10:
- System.out.println("这个月有31天");
- md=31;
- break;
- case 11:
- System.out.println("这个月有30天");
- md=30;
- break;
- case 12:
- System.out.println("这个月有31天");
- md=31;
- break;
- }
- // System.out.println(md);
- int day=0;
- for(int i=1900;i<year;i++){
- if(year%100!=0&&year%4==0||year%400==0){
- day+=366;
- }else{
- day+=365;
- }
- }
- for(int j=1;j<=month;j++){
- if(j==2){
- if(year%100!=0&&year%4==0||year%400==0){
- day+=29;
- }else{
- day+=28;
- }
- }else{
- if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){
- day+=31;
- }else{
- day+=30;
- }
- }
- }
- System.out.println("有"+day+"天");
- day-=md-1;
- System.out.println(day);
- System.out.println("日\t一\t二\t三\t四\t五\t六\t");
- int weekday=day%7;
- //System.out.println(weekday);
- for(int i=1;i<=weekday;i++){
- System.out.print("\t");
- }
- for(int i=1;i<=md;i++){
- if(day%7==6){
- System.out.print(i+"\n");
- }else{
- System.out.print(i+"\t");
- }
- day++;
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。