eclipse如何退出java程序?
我已经在我的代码中创建了一个主菜单。当用户键入q时,我希望代码停止运行。相反,它只是再次显示菜单,我应该使用什么代码来停止此操作。如果你按下任何其他字母,它就会工作。多谢各位
import java.util.Random;
public class Aaa {
AQAConsole2016 console = new AQAConsole2016();
Random random = new Random();
int boardSize;
boolean moveIsValid;
char [][] board;
int move;
char choice;
String playerName="Human";
String player2="Computer";
public Aaa() {
boardSize = 6;
do {
displayMenu();
choice = getMenuChoice(playerName);
switch (choice) {
case 'p' : playGame(playerName, boardSize);
break;
case 'e' : playerName = getPlayersName();
break;
case 'c' : boardSize = changeBoardSize();
break;
case 'm' : Multiplayer( boardSize,playerName,player2);
break;
case 'r' :readBoard(board,boardSize);
break;
case 'q' : quit();
}
}while (choice!='p'||choice!='e'||choice!='c'||choice!='m'||choice!='r'||choice!='q');
}
void quit(){
}
# 1 楼答案
这是行不通的,因为
case 'q' : quit();
只是对一个方法的调用,即当该方法完成时,它将返回到do,而您需要添加一些布尔条件,如果选择了选项菜单,则可以修改这些条件
像这样做
其中exit是一个布尔变量
在void方法中,您可以: