two dimensional array print response
I know this is against the rules but it keeps logging me out when I enter that thread for some reason.
Anyway to the point your problem is here
for (int i = 0; i< DAYS.length; i++) {
System.out.print(DAYS[i]); }
instead you want to initialise a variable outside the whole loop, then add one to i without the for loop inside.
So this is how I would do it
public void printTable(){
int start, end, count;
end = 16;
int i = 0;
count = 0;
System.out.println();
System.out.println("-----------------------");
for (start = 9; start <= end; start++){
System.out.print(start + " ");
}
for (int row = 0; row < timetable.length; row++){
System.out.println("");
for (int col = 0; col < timetable[row].length; col++){
System.out.print(timetable[row][col] + " ");
}
System.out.print(DAYS[i]);//soz I thought it was an array list :/
i++;
}
System.out.println();
System.out.println("-----------------------");
}
Hope this helps :)
To explain what I did:
What you did was you put a for loop for the days inside the large loop, therefore all the contents of the arraylist will be printed every time
What I did was made it so that i would add 1 to i every time, instead of going through the whole arraylist every run of the loop. This way every time it will run the corresponding day will print.
-Bayan-