我正在开发一款游戏,我的扫描仪遇到了一些问题.我的资源泄漏扫描程序从未关闭过.
但我以为我的扫描仪在没有关闭它之前就已经工作了.但现在不是.有人可以帮帮我吗?
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).");
}
}
Run Code Online (Sandbox Code Playgroud)