缺少值时插入短划线( - )

时间:2016-12-22 17:46:22

标签: java windows netbeans

如果星期几的值为空,我如何在日历上显示“ - ”?

以下是代码:

 public static void printCalander(int month, int year) {
    String[] monthNames = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

    //showing which month is being displayed on the yearly calendar
    System.out.println("    " + monthNames[month] + " " + year);
    System.out.println("Su Mo Tu We Th Fr Sa");
    for (int index = 0; index < obj1; index++) {
        System.out.print("  ");
    }

    //numDays is showing how many days are needed for the calendar following the user input
    for (int count = 1; count <= numDays; count++) { 
        System.out.printf("%2d ", count);

        //if the calendar reaches 7 numbers then it will take a new line 
        if (((count + obj1) % 7 == 0) || (count == numDays)) { 
            System.out.println("");
        }

    }//for
}//end of printCalendar

1 个答案:

答案 0 :(得分:0)

如果我理解正确你需要为工作日制作一个整数数组,并像使用这样的控制器一样使用它:

String[] array = new String[7];

//take inputs like this:
for(int i = 0; i<7; i++) {
    input = k.nextLine();
    if(input.equals(""))
        array[i] = "-";
        continue;
    }
    array[i] = input;
}

或保存数组中的输入并控制它。如果它有一个null元素,则将其更改为&#34; - &#34;。