I have the following issue: The values of each row of my matrix are given, with columns separated by a whitespace - so I enter all row values in a String array, remove the white spaces and parse the numbers into an int array. Now the values of each row look like 1 number "12345", while they should be "1 2 3 4 5".
How can I first separate the digits and then fill my matrix by adding the elements to each row? Thanks! Here is my code:
String n1 = input.nextLine ();
int n = Integer.parseInt(n1); //rows of the matrix
String[] arr = new String [n]; //contains all the rows of the matrix
int [] array = new int [arr.length]; // contains all the elements of the rows of the matrix without whitespace
for (int i = 0; i < arr.length; i++) {
arr [i] = input.nextLine().replaceAll("\\s+","");
array[i] = Integer.parseInt(arr[i]);
}
int matrix [][] = new int [n][arr[0].length()];