java从文本文件中读取内容并将其存储到数组中
我有一个文本文档,其中包含一个带有这些值的5x5表
5 5
39 95 99 56 41
88 8 1 48 75
3 58 13 54 80
92 72 74 25 86
30 38 3 21 2
我必须将它们添加到一个数组中,并显示最低值(即1)并告诉最低值的位置(第1行第2列)
public static void main(String[] args)
{
Scanner input;
File fileIn = new File("src/array2d/array2dtest1.txt");
System.out.println(fileIn.getAbsolutePath());
int[][] array = new int[5][5];
for(int row = 0;row<array.length;row++) {int[] column = array[row];
{
for(int columnIndex = 0; columnIndex<column.length; columnIndex++);
}
}
try
{
input = new Scanner(fileIn);
}
catch (FileNotFoundException e)
{
System.out.println(fileIn.getName() + " is not found.");
return;
}
input.close();
}
}
# 1 楼答案
如果您使用的是扫描仪,则不需要直接拆分或解析整数。默认分隔符是空格
# 2 楼答案
这段代码实际上将您的输入存储到一个数组中
# 3 楼答案
使用@vikasn91中的答案,我对其进行了一些编辑,以正确地将值分配给数组,找到数组中的最低数字及其位置:
# 4 楼答案