-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?

5
  • have you heard of Split function provided by java String class, Use that to split the content and pass your delimeters to it. Commented Nov 29, 2017 at 7:39
  • 1
    PLEASE do not downvote beginners. Just explain the problems of question in comments. Commented Nov 29, 2017 at 7: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. Commented Nov 29, 2017 at 7:48
  • @LalitVerma that's true. But some beginners do not read it. I asked to notice them with comments, not by downvote. Commented Nov 29, 2017 at 7:54
  • now this is well said @g.Irani Commented Nov 29, 2017 at 7:59

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.