标签:default pack system static def efault span util public
1 package oop; 2 3 import java.util.Scanner; 4 5 public class 万年历 { 6 public static void main(String[] args) { 7 // TODO 自动生成的方法存根 8 int zy=0;//年份天数 9 int yy=0;//月份天数 10 Scanner s = new Scanner(System.in); 11 System.out.println("请输入年份"); 12 int year = s.nextInt(); 13 System.out.println("请输入月份"); 14 int money = s.nextInt(); 15 System.out.println("总天数:"); 16 //计算总天数 17 for (int i = 1900; i <year; i++) { 18 if(i/400==0||(i%4==0&&i%100!=0)) { 19 zy+=366; 20 }else { 21 zy+=365; 22 } 23 } 24 //计算月数 25 for (int i = 1; i < money; i++) { 26 switch (i) { 27 case 1: 28 case 3: 29 case 5: 30 case 7: 31 case 8: 32 case 10: 33 case 12: 34 yy+=31; 35 break; 36 case 2: 37 if(year/400==0||(year%4==0&&year%100!=0)) { 38 yy+=28; 39 }else { 40 yy+=29; 41 } 42 break; 43 case 4: 44 case 6: 45 case 9: 46 case 11: 47 yy+=30; 48 break; 49 default: 50 return; 51 } 52 } 53 System.out.println(zy+yy); 54 int num=0;//空格数 55 num=1+(zy+yy)%7; 56 System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t"); 57 for (int i = 0; i < num; i++) { 58 System.out.print("\t"); 59 } 60 for (int i = 1; i < 31; i++) { 61 System.out.print(i+"\t"); 62 if((num+i)%7==0) { 63 System.out.println(); 64 } 65 } 66 67 } 68 }
标签:default pack system static def efault span util public
原文地址:https://www.cnblogs.com/weiyongguang/p/9691370.html