【发布时间】:2017-03-12 04:06:19
【问题描述】:
我想从此文件文本中获取行和列的长度。我怎样才能做到这一点?谢谢!
in.txt
2 1 1 8
1 1 4 15
0 3 2 9
public static void main(String[] args) {
int[][] arr = new int[3][4];
File inputFile = new File("in.txt");
try {
Scanner scanF = new Scanner(inputFile);
for (int i = 0; i < 3; i++) {
String line = scanF.nextLine();
String valVar[] = line.split(" ");
for (int j = 0; j < 4; j++) {
arr[i][j] = Integer.parseInt(valVar[j]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
-
长度是什么意思?