0

Help with enhanced for loop

I need to make calendar in one array. This is an exercise from my Java manual. Below I only write example, but I do not understand why it i doesn't work. Maybe You can help me. int count = 31; int month = 1; int year = 2016; byte x = 0; byte day = 1; String [] [] [] date = New String [count] [month+1] [month] ; for(int i =0;i>count;i++) { date[x++] [month] [0] = day +"/" +month+"/" +year; } for(String [] [] [] printDate: date) { System.out.print(printDate); } Compilator Say that the last one "for" is to many []. It should be [] []. But it doesn't worked.

8th Jan 2019, 5:50 PM
Kamil Janiak
Kamil Janiak - avatar
1 Answer
0
Enhanced loops only iterates 1 dimension of an Array. The loop to fill the Array isn't correct. Some Code to play with: Hope it helps - good luck ;-) int count = 31; int month = 1; int year = 2016; byte x = 0; byte day = 1; String [] [] [] date = new String [count] [month+1] [count] ; for(int i =0;i<count;i++) { date [0] [month] [i] = i+1 +"/" +month+"/" +year; } // print only one Array-Level for(String printDate: date[0][1]) { System.out.println(printDate); } // print two Array-Levels for(String[] printDatem: date[0]) for(String printDate: printDatem ) { System.out.println(printDate); }
9th Jan 2019, 1:07 PM
PapaBT
PapaBT - avatar