我正在开发一款游戏,并且遇到了扫描仪的一个小问题。 我得到一个永不关闭的资源泄漏扫描器。扫描仪从不关闭
但我认为我的扫描仪之前没有关闭它。 但现在不是。任何人都可以帮助我吗?
import java.util.Scanner;
public class Main {
public static final boolean CHEAT = true;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amountOfPlayers;
do {
System.out.print("Select the amount of players (1/2): ");
while (!scanner.hasNextInt()) {
System.out.println("That's not a number!");
scanner.next(); // this is important!
}
amountOfPlayers = scanner.nextInt();
while ((amountOfPlayers <= 0) || (amountOfPlayers > 2));
System.out.println("You've selected " + amountOfPlayers+" player(s).");
}
}
一些更好的使用你怎么能告诉你的扫描仪无法工作了?你看到什么行为? – 2013-03-25 11:25:13