62,568
社区成员




//正确代码
import javax.swing.*;
public class GuessGame {
public static void main(String args[]) {
System.out.println("猜价格,请输入您认为这件商品的价格,您有10次机会。");
int guessprice = 0;
int price = (int) (Math.random() * 100 + 250);
// 输入价格
for (int i = 1; i <= 10; i++) {
while (true) {
try {
String P = JOptionPane.showInputDialog("请输入价格");
guessprice = Integer.parseInt(P);
break;
} catch (Exception e) {
System.out.println("对不起,请输入正确的格式");
}
}
// 判断价格
if (guessprice > price) {
System.out.println("对不起,大了");
}
if (guessprice < price) {
System.out.println("对不起,小了");
}
if (guessprice == price) {
System.out.println("恭喜你答对了,10万元大奖就是您的!");
System.out.println("请问您还想继续玩吗?是请打“Y”,否则“N”");
// 判断是否继续玩
String YesOrNo;
do {
YesOrNo = JOptionPane
.showInputDialog("请问您还想继续玩吗?是请打“Y”,否则“N”");
} while (!YesOrNo.equals("Y") || !YesOrNo.equals("N"));
if (YesOrNo.equals("Y")) {
i = 1;
} else
System.exit(1);
}
}
System.out.println("Game Over..");
}
}
while(YesOrNo!==Y||YesOrNo!==N);
//你的Y定义在那儿呢。 同时 有 !== 这个运算符么?