我正在开发一款游戏,但我的扫描仪遇到了一个小问题。我得到了一个从未关闭的资源泄漏扫描器。
但我认为我的扫描仪之前没有关闭它就可以工作。但现在不是了。任何人都可以在这里帮助我吗?
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).");
}
}