我是编程新手,我一直在编写一个简单的程序来创建一个继续显示错误的石头剪刀布游戏。在启动/运行该程序时,它似乎无法识别变量 Rock Paper 和 Scissors 并直接进入 else 条件。另外,当我尝试解析之后
int exit = 4;
while (exit != userchoice){
JOptionPane.showInputDialog("Choose wisely. Enter:\n 1 for Rock \n 2 for Paper "
+ "\n 3 for Scissors \n or 4 to Exit:\n");
该程序就停在那里,所以我仍然很难找到任何其他方式。另外,这个程序将如何以我要去的条件结束?我仍然不明白如何结束这个循环,因为我认为用一个简单的最终括号它会在满足条件后结束循环,在这种情况下输入数字 4。
帮助将不胜感激。谢谢你。
public static void main(String[] args) {
String inString = null;
int compchoice = (int)(Math.random() * 3);
int userchoice = 0;
int Rock = 1, Paper = 2, Scissors = 3;
Scanner input = new Scanner(System.in);
JOptionPane.showMessageDialog(null,
"Welcome to JanKenPo! It is You Vs. The Computer\n");
int exit = 4;
while (exit != userchoice){
JOptionPane.showInputDialog("Choose wisely. Enter:\n 1 for Rock \n 2 for Paper "
+ "\n 3 for Scissors \n or 4 to Exit:\n");
if (userchoice == Rock && compchoice == Paper) {
JOptionPane.showMessageDialog(null, "Paper covers Rock! You win this Round.");
}
else if (userchoice == Rock && compchoice == Scissors){
JOptionPane.showMessageDialog(null, "Rock crushes Scissors! You win this Round.");
}
else if (userchoice == Scissors && compchoice == Paper){
JOptionPane.showMessageDialog(null, "Scissors cuts Paper! You win this round.");
}
else if (userchoice == Paper && compchoice == Rock){
JOptionPane.showMessageDialog(null, "Paper Covers Rock! Computer wins this Round.");
}
else if (userchoice == Paper && compchoice == Scissors){
JOptionPane.showMessageDialog(null, "Scissors cuts Paper! Computer wins this Round.");
}
else if (userchoice == Scissors && compchoice == Rock){
JOptionPane.showMessageDialog(null, "Rock crushes Scissors! Computer wins this Round.");
}
else if (userchoice == compchoice){
JOptionPane.showMessageDialog(null, "It's a Tie! Both you and the computer chose the same object.");
}
else{
exit = Integer.parseInt(inString);
}
}
}
JOptionPane.showMessageDialog(null, "Good Bye!");
}