The basic calendar can switch to the upper and lower months

From , 5 Years ago, written in Java, viewed 80 times.
URL https://pastebin.vip/view/e22dd5da
  1. import java.util.Scanner;
  2.  
  3. public class code1 {
  4.         public static void main(String[] args) {
  5.                 Scanner in = new Scanner(System.in);
  6.                 System.out.println("请输入你想查询的年份(至少为1900年):");
  7.                 int year = in.nextInt();
  8.                 System.out.println("请输入你想查询的月份:");
  9.                 int month = in.nextInt();
  10.                 int flag = 0;
  11.                 while (flag == 0) {
  12.                         int sum = 0;
  13.                         int num = 0;
  14.                         for (int date = 1900; date < year; date++) {
  15.                                 if (date % 4 == 0 && date % 100 != 0 || date % 400 == 0) {
  16.                                         sum = sum + 366;
  17.                                 } else {
  18.                                         sum = sum + 365;
  19.                                 }
  20.                         }
  21.                         for (int date1 = 1; date1 < month; date1++) {
  22.                                 if (date1 == 1 || date1 == 3 || date1 == 5 || date1 == 7 || date1 == 8 || date1 == 10 || date1 == 12) {
  23.                                         sum = sum + 31;
  24.                                 } else if (date1 == 2) {
  25.                                         if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
  26.                                                 sum = sum + 29;
  27.                                         } else {
  28.                                                 sum = sum + 28;
  29.                                         }
  30.                                 } else {
  31.                                         sum = sum + 30;
  32.                                 }
  33.                         }
  34.                         sum = sum + 1;
  35.                         System.out.println("**************************");
  36.                         System.out.println("\t下面是"+year+"年"+month+"月"+"的日历");
  37.                         System.out.println("**************************");
  38.                         System.out.println("日\t\t\t\t\t\t六");
  39.                         for (int i = 0; i < (sum % 7); i++) {
  40.                                 System.out.print(" \t");
  41.                         }
  42.                         if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 | month == 12) {
  43.                                 num = 31;
  44.                         } else if (month == 2) {
  45.                                 if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
  46.                                         num = 29;
  47.                                 } else {
  48.                                         num = 28;
  49.                                 }
  50.                         } else {
  51.                                 num = 30;
  52.                         }
  53.  
  54.                         for (int i = 1; i <= num; i++, sum++) {
  55.                                 System.out.print(i);
  56.                                 if (sum % 7 == 6) {
  57.                                         System.out.println();
  58.                                 } else {
  59.                                         System.out.print("\t");
  60.                                 }
  61.                         }
  62.                         System.out.println();
  63.                         System.out.println("请选择1、2、3");
  64.                         System.out.println("1、观看上一个月的日历");
  65.                         System.out.println("2、观看下一个月的日历");
  66.                         System.out.println("3、结束");
  67.                         int select = in.nextInt();
  68.                         if (select == 1) {
  69.                                 month = month - 1;
  70.                                 if (month == 0) {
  71.                                         year = year - 1;
  72.                                         month = 12;
  73.                                 }
  74.                                 flag = 0;
  75.                         } else if (select == 2) {
  76.                                 month = month + 1;
  77.                                 if (month == 13) {
  78.                                         year = year + 1;
  79.                                         month = 1;
  80.                                 }
  81.                                 flag = 0;
  82.                         } else {
  83.                                 flag = 1;
  84.                         }
  85.                 }
  86.         }
  87. }

Reply to "The basic calendar can switch to the upper and lower months"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website