【发布时间】:2018-11-05 02:27:27
【问题描述】:
文本文件包含随机符号,我想计算数字 0 - 9。
我正在努力弄清楚如何将文本文件读入数组,如何正确计算特定数字在数组中的出现次数,然后使用方法显示出现次数。
到目前为止,这是我的代码:
// Get the filename.
System.out.print("Enter the filename: ");
String filename = keyboard.nextLine();
// Open the file.
File file = new File(filename);
Scanner inputFile = new Scanner(file);
char [] charMap = new char [1380];
// Read lines from the file until no more are left.
while (inputFile.hasNext())
{
// Read the map.
String map = inputFile.nextLine();
charMap = map.toCharArray();
// Display the map.
System.out.println(charMap);
}
// Close the file.
inputFile.close();
} }
【问题讨论】: