Read .txt file into 2D Array

前端 未结 4 1645
甜味超标
甜味超标 2020-11-28 12:21

There are a few of these topics out there, but this problem has a slight twist that makes it different.

I\'m focused on only half of a larger problem. I\'m sure man

4条回答
  •  [愿得一人]
    2020-11-28 13:05

    First, test out the Scanner results. I don't think those delimiters will work. (BTW, Scanner's nextInt() method is handy.)

    If you can assume the input is a square matrix, scanning the first line will reveal how many integers it contains. Then you can (re)allocate the arrays. Then process all the lines, including the first line that you already scanned.

    Then you can set matrix = new int[n][n];

提交回复
热议问题