For an assignment I have to read an input which looks like this:
. . . . . . . . . . . . . * .
. . . . . . . . . . . . * . .
. . . . . . . . . . . . * * *
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
* * * * * * * * . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
and store it in an array which contains Strings. For now I've come up with this, however, I don't know how to arrange the input in such a way that it can be stored as an array.
void readInputField(){
String inputField; //string in which input is stored
inputField = sc.nextLine(); //scans the input
String[][] fieldParts; //array in which I want to store Strings of inputField
fieldParts = new String[height][width]; //width and height are determined
//by earlier scanner input and correspond to the dimensions of the input array
fieldParts = inputField.split(" "); //error on this line, how to split the input
//as parts of the array?
}
char[][]instead of aString[][]sinceStrings typically hold more than one character, but each cell of your array holds only one character (if I understood you correctly)fieldPartsis declared to hold 2D arrayString[][]but result ofsplitis 1D arrayString[]. Anyway are you sure that values ofheightandwidthwill be correct (15 in this case)?