我在读取输入时遇到问题,任何人都可以帮助我。
每行输入都必须为整数:X e Y,并用空格分隔。
12 1
12 3
23 4
9 3
我在java中使用这段代码,但不起作用,它只读取第一行,有人可以帮助我吗?
String []f;
String line;
Scanner in=new Scanner(System.in);
while((line=in.nextLine())!=null){
f=line.split(" ");
int X,Y;
X=Integer.parseInt(f[0]);
Y=Integer.parseInt(f[1]);
if(X<=40 && Y<=40)
metohod(X,Y);
line=in.nextLine();
}
}
最佳答案
您正在调用 nextLine 两次,一次是在同一时间,另一个是 linha = xxx; linha 到底是什么?试试这个
BufferedReader reader = new BufferedReader(...);
while((line = reader.readLine())!=null) {
String[] f = line.split(" ");
int X,Y;
X=Integer.parseInt(f[0]);
Y=Integer.parseInt(f[1]);
}
关于java - 在 Java 中读取输入 - 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2965794/