如何解决为什么scanner.hasNextInt() 不正确?
这里是if,用于检查scanner.hasNextInt() 发生了什么:
if (scanner.hasNextInt()){
System.out.println("we");
}else{
System.out.println("kill me");
}
public class LightBot {
String map[] [];
int crow,ccol,cdir;
LightBot(String fileName,int row,int col,int dir){
try {
Scanner scanner= new Scanner(fileName);
int [] tall=new int[100];
int i=0;
FileReader inputFil = new FileReader(fileName);
BufferedReader in = new BufferedReader(inputFil);
String s =in.readLine();
System.out.println("r");
if (scanner.hasNextInt()){
System.out.println("we");
}else{
System.out.println("kill me");
}
while(scanner.hasNextInt()){
System.out.println("sru gjl g");
try {
tall[i++] = Integer.parseInt(s);
System.out.println("ff");
}
catch (NumberFormatException ex) {
System.out.println("WTF");
continue;
}
}
}catch (IOException error) {
System.out.println("error");;
}
}
public static void main(String args[]){
LightBot l= new LightBot("test.txt",0);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。