日期时间都对应得上,但有个问题,为啥只有2019年4月第一行的空白的

package java基础.万年历制作;

import java.util.Scanner;

public class Calader{

 public static void main(String[] args) {
        while (true) {
        int sum = 0;

       Scanner sc = new Scanner(System.in);
       System.out.println("查询的年份");
       int year = sc.nextInt();
      System.out.println("查询的月份");
      int month = sc.nextInt();

   for (int i = 1900; i < year; i++) {
        if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0)) {
                sum += 366;
             } else {
                         sum += 365;
                   }
     }
          int currentDay = 0;// 当月天数
         int totalDay = 0;// 当前年份到当前月份的总天数
         for (int i = 1; i <=month; i++) {
        int day = 0;
    switch (i) {
                case 4:
                case 6:
                case 9:
               case 11:
                           day = 30;
                   break;    
             case 2:
                      if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
                                  day = 29;
    
                         } else {
                                   day = 28;
                                }
                 break;
            default:
                    day = 31;
    
              break;
          }
    if (i == month) {
     currentDay = day;
    }
    totalDay += day;

   }
  
   int allDays=sum+totalDay;//所有的天数的总和
   int week = (allDays - currentDay) % 7;//多了一个所以减去一个月
   System.out.println(week);
   System.out.println("=====================================================");
   System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日");

   int blank = 0;
   for (int i = 1; i <=week; i++) {
    blank++;
    System.out.print("\t");
   }
   // 打印天数
   for (int i = 1; i <= currentDay; i++) {
    if (blank % 7 == 0) {
     System.out.println();// 如果占位符和天数计数超过7则换行
    }
    blank++;
  
    System.out.print(i + "\t");
   }
  }
 }
}


空空空空空空啊
浏览 595回答 1
1回答

EnchantF

做的没什么问题,这是输出的问题,2019年4月的  week =0,然后 blank=0;然后就System.out.println()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java