I've been asked to read a file and take the text in there and convert them to a 2d array. Since Eclipse is a pain and wont open/read my text file, I made a test in the class that uses an individually initialized 2d array. My problem is that I don't know to put the parseInt'ed array back into the new one. Or how to use that to form a new 2d array. Here's my code: public static void main(String[] args) {
String[][] tester = new String[][] { { "-1 2 3 0" }, { "-1 3 4 0" }, { "-1 3 -4 0" }, { "-1 -3 4 0" } };
int row = 0;
int col = 0;
int count = 0;
int[][] formula = new int[4][];
while (count < 4) {
String temp = tester[row][col];
String[] charArray = temp.split("\\s+");
int[] line = new int[charArray.length];
for (int i = 0; i < charArray.length; i++) {
String numAsStr = charArray[i];
line[i] = Integer.parseInt(numAsStr);
//what to do here??
}
row++;
count++;
}
System.out.println(Arrays.deepToString(formula).replace("], ",
"]\n"));
}
}
I want to generate an array that reads like this:
-1 2 3 0
-1 3 4 0
-1 3 -4 0
-1 -3 4 0
How can I accomplish this?