我正在寻找一些细节,以便更好地了解扫描仪库,我用它来完成编程挑战扫雷问题。
我收到一个看起来像这样的文件
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0
我在下面写了一小部分代码。
public static void main(String[] args) throws FileNotFoundException {
Scanner input = null;
try{
input = new Scanner(new BufferedReader(new FileReader("Text.txt")));
while(input.hasNextLine()){
if(input.hasNextInt()){
int i = input.nextInt();
int j = input.nextInt();
System.out.println(i);
System.out.println(j);
}
else{
System.out.println("No Int");
}
}
}
finally{
input.close();
}
}
此代码首先检查文件是否有新行要读取,如果行有整数,则将它们放入变量i和j中。但它只给了我4 4和No Int的其他一切。如果有人可以解释为什么会这样,那么我可以更好地了解扫描仪如何运作,这将是非常好的