-1

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?

rghome
  • 8,529
  • 8
  • 43
  • 62
  • have you heard of `Split` function provided by java `String` class, Use that to split the content and pass your delimeters to it. – Rishal Nov 29 '17 at 07:39
  • 1
    PLEASE do not downvote beginners. Just explain the problems of question in comments. – Gholamali Irani Nov 29 '17 at 07:45
  • Check out the duplicate link. It is not exactly the same, but you should be able to use the example. Your sample data doesn't really make sense since there should be six data items for a 3x2 matrix. – rghome Nov 29 '17 at 07:48
  • @LalitVerma that's true. But some beginners do not read it. I asked to notice them with comments, not by downvote. – Gholamali Irani Nov 29 '17 at 07:54
  • now this is well said @g.Irani – Lalit Verma Nov 29 '17 at 07:59

1 Answers1

0

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];
Dorukhan Arslan
  • 2,676
  • 2
  • 24
  • 42