例如下面的代码
while (lineScan.hasNextLine()) {
int x = lineScan.nextInt();
x = lineScan.nextInt();
x = lineScan.nextInt();
x = lineScan.nextInt();
x = lineScan.nextInt();
System.out.println(x + "\n");
}
将打印出每五个整数。
有没有一种简单的方法可以跳过每五个整数?
最佳答案
while (lineScan.hasNextLine()) {
for(int i=0; i<5; i++)
x = lineScan.nextInt();
System.out.println(x + "\n");
}
或
while (lineScan.hasNextLine()) {
for(int i=0; i<4; i++)
lineScan.nextInt();
x = lineScan.nextInt();
System.out.println(x + "\n");
}
看起来很原始,但它确实有效。
关于java - 在一系列整数上使用扫描仪时,如何跳过一些整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6085644/