Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>as far as I saw in your comment you would like to have also an 2D array with boolean if the character is 'X' so I filled two arrays in my code - one actually with the character and one with true or false, depending of the character is 'X' or not. There are also some system.outs to better understand how it works. I am removing newline characters ('\n') when appearing (dont know if you want that or not)</p> <pre><code>public static void main(String[] args) { final int cellSize = 30; // grid size char[][] chargrid = new char[cellSize][cellSize]; boolean[][] chargridIsX = new boolean[cellSize][cellSize]; File inputFile = new File("input.txt"); FileInputStream is = null; try { is = new FileInputStream(inputFile); int n = -1; int rowCount = 0; int colCount = 0; while( (n=is.read()) !=-1){ char readChar = (char) n; if(readChar!='\n'){//This removes the linebreaks - dont know if you want that chargrid[rowCount][colCount] = readChar; if(readChar=='X') { // Here actually set true or false if character is 'X' chargridIsX[rowCount][colCount] = true; System.out.println("row "+rowCount+" col "+colCount + " = " + readChar + " " + true); }else { chargridIsX[rowCount][colCount] = false; System.out.println("row "+rowCount+" col "+colCount + " = " + readChar+ " " + false); } if(rowCount++ &gt;= cellSize-1){ System.out.println("new col"); rowCount = 0; if(colCount++ &gt;= cellSize-1){ //ARRAY IS FULL System.out.println("full"); break; } } } } } catch (FileNotFoundException e) { //could not get Inputstream from file e.printStackTrace(); } catch (IOException e) { // problem with the inputstream while reading e.printStackTrace(); } </code></pre> <p>btw. I am reading character for character from an inputstream instead of using scanner, hope that is okay - otherwise let me know</p> <p>For what ever this might be good</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload