java - reversing array data from * to empty and empty to * -


so have created 2d array called pixels. have written method flip array on vertical axis , rotate array once 90 degrees. know simple, , overlooking simple, life of me cannot figure out how reverse data in array. array hold blank values , * values print picture. need create method reverse * empty , empty spaces *.

yes homework (lab actually) , if explain me how method work sure can write on own. looking pointers here. thanks.

edit:

my code won't work, operand mismatch error char[][] , char

   public void invert ( ){      if (pixels == '*'){          pixels = ' ';     }     else{         pixels = '*';     }        }  

code creates array:

               private char[][] pixels =      {  { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },         { ' ', '*', '*', '*', '*', '*', ' ', ' ' },         { ' ', '*', ' ', ' ', ' ', ' ', ' ', ' ' },         { ' ', '*', ' ', ' ', ' ', ' ', '*', ' ' },         { ' ', '*', '*', '*', ' ', ' ', ' ', ' ' },         { ' ', '*', ' ', ' ', ' ', '*', ' ', ' ' },         { ' ', '*', ' ', ' ', ' ', ' ', ' ', '*' },         { ' ', '*', '*', '*', '*', '*', ' ', ' ' },          { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' } }; 

you have walk matrix, not use in conditional clause. seems me pixels of type char[][].

you need iterate on and, each element, like:

if (pixels[i][j] == '*'){     pixels[i][j] = ' '; } else{     pixels[i][j] = '*'; } 

, i , j current coordinates.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -