java - Filling a Two-Dimensional Array -


i'm encountering problem filling in rows of 2 dimensional array. have alternate between 3 colors, red, white , blue..

public void makepattern() {     (int = 0; < rows; i++) {         (int j = 0; j < columns; j++) {             if (rows%3 == 0 && < 15) {                 colors[i][j] = color.red;                 = + 3;             }             else if (rows%2 == 1 && < 15) {                 = 1;                   colors[i][j] = color.white;                 = + 3;             }         }     } 

row = 15
column = 20

i believe code means every third row starting 0 15 (0, 3, 6, 9, 12, 15) fill red. white ever row starting 1 until 15 , adding 3 (1, 4, 7, 10, 13) fill row. there's still matter of blue, after understand first. end filling entire array red. need fix code, more importantly need understanding logic of how works, advice or tip fine. :(

my answer hint, because looks homework me.

you should change following line -

if (rows%3 == 0 && < 15) 

to -

if (i % 3 == 0) 

this makes sure selecting rows divisible 3 (and first row index 0 because checking first).

your previous condition checking row % 3. if row value 15, true every row. , last i < 15 bit true.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -