arrays - How to use System.in.read() in java? -


i need input , load chars in boolean 2-d array. if char x, mark array element true; else if char ., mark array element false.

here design:

boolean[][] array = new boolean[2][2];  (int = 0; < 2; i++) {      (int j = 0; j < 2; j++) {         if (system.in.read() == '.') {             array[i][j] = false;         } else if (system.in.read() == 'x') {             array[i][j] = true;         }     } } 

and, example, if type in .... or xxxx, not produce correct result. other input result not correct.

so how deal this?

you reading character second time in loop if first character not '.'.

you should read 1 character per loop. save character in variable before if statement, , compare variable '.' , 'x' in turn.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

c++11 - Intel compiler and "cannot have an in-class initializer" when using constexpr -

.net - How to detect a double-click outside of vb.net form -