printing array out of bounds java -


i have array of objects looking this:

1: [volvo, 200] , [jaguar, 900]
2: [bmw, 300]
3: [skoda, 100] , [(no input)] , [(no input)]


this method print areas value (with formating inside not issue). out of bound error... need do? thank you!

        public static void printmat(car[][] carmat){         int row = 0;         int column = 0;         while ((carmat[row][column] != null)){             system.out.printf("( %-8s : %,9d )", carmat[row][column].getname(), carmat[row][column].getprice());             if (column == carmat[row].length - 1){                 system.out.print("\n");                 row++;                 column = 0;             } else {                 column++;             }         }     } 

you have checked if going off end of current row, good, haven't checked if have run out of rows.

after row++, add in check see if row has gone off end of carmat array.

if (row >= carmat.length)     break; 

that assumes have @ least 1 row. may want check if have @ least 1 row before enter while loop.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -