1 回答
TA贡献1828条经验 获得超13个赞
您必须:
读取第一行
拆分它以获得尺寸
阅读下一行(关于尺寸)
读取特殊字符 (
@
)重复
读取您在那里的第一个数组:
static void readFile() throws IOException {
BufferedReader reader;
reader = new BufferedReader(new FileReader("file.txt"));
String firstDimension = reader.readLine();
String[] split = firstDimension.split(" ");
int firstX = Integer.parseInt(split[0]);
int firstY = Integer.parseInt(split[0]);
int[][] first = new int[firstX][firstY];
for (int i = 0; i < firstX; i++) {
String[] line = reader.readLine().split(" ");
for (int j = 0; j < firstY; j++) {
first[i][j] = Integer.parseInt(line[j]);
}
}
// Read "@"
reader.readLine();
System.out.println(Arrays.deepToString(first));
}
和基于输入:
3 3
12 34 45
34 -12 56
76 12 -1
@
3 3
8 13 45
67 0 12
12 -12 3
输出应为:
[[12, 34, 45], [34, -12, 56], [76, 12, -1]]
添加回答
举报