Java 我的公历没有';不能正确显示

Java 我的公历没有';不能正确显示,java,Java,我的公历像楼梯一样显示,每行从1开始不断重复。我做错了什么 package unit8_1gregoriancalendar; import java.util.GregorianCalendar; @SuppressWarnings("serial") // This will suppress problems with the class public class Lab8_1GregorianCalendar extends GregorianCalendar { //

我的公历像楼梯一样显示,每行从1开始不断重复。我做错了什么

 package unit8_1gregoriancalendar;
 import java.util.GregorianCalendar;

 @SuppressWarnings("serial") // This will suppress problems with the class
 public class Lab8_1GregorianCalendar extends GregorianCalendar 
 {
 // Create a Gregorian calendar type        
 static GregorianCalendar gregorianObject = new GregorianCalendar();

public static void main(String[] args) 
{
// This gets the current month, but need to add one for January = 0 in the            GregorianCalendar
int currentMonth = gregorianObject.get(Lab8_1GregorianCalendar.MONTH)+1;
int currentYear = gregorianObject.get(Lab8_1GregorianCalendar.YEAR);

printOutMonth(currentYear, currentMonth);
} // This ends Main() Method

static void printOutMonth(int year, int month) 
{
    int startDay = gregorianObject.get(Lab8_1GregorianCalendar.DAY_OF_WEEK);
    int monthDaysEnd = howManyDays(month,year);

    //This Displays the Calendar Header
    String monthName = getMonthName();
    System.out.println();
    System.out.println("          " + monthName + " " + year);
    System.out.println("----------------------------");
    System.out.println(" Sun Mon Tue Wed Thu Fri Sat");

    fillTheCells(startDay, monthDaysEnd);

} // This ends printOutMonth Method

static int howManyDays(int month, int year)
{
    switch(month)
    {
        case 1: return 31;
        case 2:{ if (gregorianObject.isLeapYear(year))
                    return 29;
                 else
                    return 28;
               }
        case 3: return 31;
        case 4: return 30;
        case 5: return 31;
        case 6: return 30;
        case 7: return 31;
        case 8: return 31;
        case 9: return 30;
        case 10: return 31;
        case 11: return 30;
        case 12: return 31;
        default: return 30;
    } // month switch case
}  // this ends howManyDays method
static String getMonthName()
{
    int monthIndicator = gregorianObject.get(Lab8_1GregorianCalendar.MONTH);
        switch (monthIndicator)
        {
            case 0: return "January";
            case 1:return "February";
            case 2: return "March";
            case 3: return "April";
            case 4: return "May";
            case 5: return "June";
            case 6: return "July";
            case 7: return "August";
            case 8: return "September";
            case 9: return "October";
            case 10: return "November";
            case 11: return "December";
            default: return "Month";
        } // This ends monthIndicator Switch Structure
}   // This ends getMonthName

static void fillTheCells(int intStartDay, int innerMonthDaysEnd)
{   //The dayCellCount loop = 7 days per week
    // Tells it to print what fits on that week AND only til end of month
    int dayCellCount=1;
    for(int weekCellCount=1; weekCellCount <= 6; weekCellCount++)
    {
        if(weekCellCount==1);
            dayCellCount=1;

        while((dayCellCount<=weekCellCount*7)&&((dayCellCount-intStartDay)<=innerMonthDaysEnd))
        {
            //Print 4 blanks per day until you get to where the month begins
            if(dayCellCount<=intStartDay)
            {
                System.out.print("    ");
            } 
            // This will Print 3 blanks and the date if date has just 1 digit
            else if(dayCellCount-intStartDay<10)
            {
                System.out.print("   "+(dayCellCount-intStartDay));
            }
            // This will Print 2 blanks and the date if the date has 2 digits until the end of month
            else if(dayCellCount-intStartDay <= innerMonthDaysEnd)
            {
                System.out.print("  " +(dayCellCount-intStartDay));
            }
            // This will get the dayCellCount to step from day to day
            dayCellCount++; 
        } // This ends the dayCellCount

        System.out.println();
    } // This ends the weekCellCount loop
    intStartDay=(intStartDay+innerMonthDaysEnd)%7;       
} // This ends fillTheCells() Method
} // This ends the Lab8_1GregorianCalendar Class
package unit8\u 1regoriancalendar;
导入java.util.GregorianCalendar;
@SuppressWarnings(“serial”)//这将禁止类出现问题
公共类Lab8_1GregorianCalendar扩展了GregorianCalendar
{
//创建公历类型
静态GregorianCalendar gregorianObject=新的GregorianCalendar();
公共静态void main(字符串[]args)
{
//它获取当前月份,但需要在GregorianCalendar中为1月=0添加一个
int currentMonth=gregorianObject.get(Lab8_1GregorianCalendar.MONTH)+1;
int currentYear=gregorianObject.get(Lab8_1GregorianCalendar.YEAR);
打印输出月份(当前年、当前月);
}//这结束Main()方法
静态无效打印输出月(整数年,整数月)
{
int startDay=gregorianObject.get(Lab8\u 1regoriancalendar.DAY\u周);
int monthDaysEnd=多少天(月,年);
//这将显示日历标题
字符串monthName=getMonthName();
System.out.println();
系统输出打印项次(“+月名+”+年);
System.out.println(“-------------------------------”;
System.out.println(“星期一星期二星期三星期四星期五星期六”);
填充单元格(开始日期、月日和发送日期);
}//这将结束printOutMonth方法
静态整数多少天(整数月,整数年)
{
开关(月)
{
案例1:返回31;
案例2:{如果(gregorianObject.isLeapYear(年))
返回29;
其他的
返回28;
}
案例3:返回31;
案例4:返回30;
案例5:返回31;
案例6:返回30;
案例7:返回31;
案例8:返回31;
案例9:返回30;
案例10:返回31;
案例11:返回30;
案例12:返回31;
默认值:返回30;
}//月开关箱
}//这将结束howManyDays方法
静态字符串getMonthName()
{
int monthIndicator=gregorianObject.get(Lab8\u 1regoriancalendar.MONTH);
开关(显示器)
{
案例0:返回“一月”;
案例1:返回“二月”;
案例2:返回“三月”;
案例3:返回“四月”;
案例4:返回“可能”;
案例5:返回“六月”;
案例6:返回“七月”;
案例7:返回“八月”;
案例8:返回“9月”;
案例9:返回“十月”;
案例10:返回“11月”;
案例11:返回“12月”;
默认值:返回“月”;
}//这结束了MontIndicator开关结构
}//这就结束了
静态空白填充单元格(int int intStartDay、int INTINNERMONTHDAYSEND)
{//dayCellCount循环=每周7天
//告诉它在那个星期打印适合的内容,直到月底
int dayCellCount=1;

对于(int-weekCellCount=1;weekCellCount
if(weekCellCount==1);欢迎使用Stackoverflow。如果有错误/异常堆栈,请发布。如果不需要使用旧的(设计糟糕的)日期API,请查看,或者如果您使用Java 7或更低版本,请查看。这些API有一个很好的日期算法工具集。
if(weekCellCount==1); <-----