2016-12-22 4 views
-1

Wie bekomme ich ein '-' in meinem Kalender, wenn der Wert für einen Wochentag leer ist? HierEinfügen eines Gedankenstrichs (-), wenn ein Wert fehlt

ist der Code:

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 

Antwort

0

, wenn ich das richtig verstanden u brauchen ein Integer-Array für den Wochentagen zu machen und es wie ein Controller wie folgt verwenden:

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; 
} 

oder speichern Eingaben in ein Array und steuern Sie es. Wenn es ein Nullelement hat, ändern Sie es in "-".

Verwandte Themen