If I had a file text:
3@2/3@9@1
@
and /
are delimiters,
The first two numbers will always be the size of the matrix
In order to code this I would have to run a while loop, then int row and column to equal the scanned text?
If I had a file text:
3@2/3@9@1
@
and /
are delimiters,
The first two numbers will always be the size of the matrix
In order to code this I would have to run a while loop, then int row and column to equal the scanned text?
First, split your text using the delimiter "/"
:
String text = "3@2/3@9@1";
String[] splits = text.split("/");
Now, splits[0]
includes "3@2"
and splits[1]
includes "3@9@1"
.
Split the string splits[0]
using the delimiter "@"
:
String[] dims = splits[0].split("@");
String dims[0]
is the row value 3
and dims[1]
is the column value 2
.
Parse dims to integer in order to use them in construction of your matrix:
int r = Integer.parseInt(dims[0]);
int c = Integer.parseInt(dims[1]);
Create your matrix:
int[][] matrix = new int[r][c];