import java.util.Scanner;
public class Craps5 {
public static void main(String[] args) {
System.out.println("Welcome " + "Do you want to play craps? y/n");
Scanner scan = new Scanner(System.in);
String condition = new String(scan.next());
int money = 10;
while (condition.equals("y"))
{
System.out.println("Craps:");
System.out.println("You have $" + money + ". How much do you want to bet?");
int bet = scan.nextInt();
System.out.println("Do you want to bet on pass or don't pass?");
String pass = new String(scan.next());
int dice;
dice = (int)(6.0*Math.random()+1.0)+ (int)(6.0*Math.random() +1.0);
if (dice == 2 || dice == 3 || dice == 12){
if (pass.equals("pass")) {
money = money - bet;
System.out.println("You lose: " + dice); }
else {
money = money + bet;
System.out.println("You win: " + dice);
}
}
if (dice == 7 || dice == 11) {
if (pass.equals("don't"))
money = money + bet;
System.out.println("You win: " + dice);
}
else {
int point = dice;
System.out.println("Point: " + point);
while (true){
dice = (int)(6.0*Math.random() + 1.0) + (int)(6.0*Math.random() + 1.0);
System.out.println("new roll: " + dice);
if (dice == point) {
money = money + bet;
System.out.println("Got point, you have won: $" + bet);
}
break;
}
if (dice == 7) {
System.out.println ("Lost with a 7");
}
else System.out.println("winner");
}
System.out.println("Would you like to play again? y/n");
condition = new String(scan.next());
}
}
}
当您下注不通过时,在询问您是否要再次玩游戏后,代码就会停止。
有人知道如何解决此问题吗?一如既往,在此先感谢您,谢谢!!请知道我是AP Computer Science课程的初学者,因此感谢您的帮助。我已经尝试过在Reddit等其他网站上寻求帮助,并与我的合作伙伴一起工作,但这是我们所能做到的