我已经为程序完成了一切,但它告诉我,“其他if”将不起作用,因为我没有“if”,但我有上面的“if”权限它。我试图让他们都“如果”看看它是否有效,但随后它只是让玩家每次都不能退出。我不知道我做错了什么。我感谢任何帮助。谢谢。老虎机代码问题
import java.util.Scanner;
import java.util.Random;
public class RayokovichD_Homework2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int Coins = 1000;
int Wager;
System.out.println("Slot Machine");
System.out.println("You have " + Coins + " coins.");
System.out.println("Press 0 to exit, any other number to play that many coins per spin.");
while (Coins > 0)
{
int x = new Random().nextInt(9);
int y = new Random().nextInt(9);
int z = new Random().nextInt(9);
Wager = input.nextInt();
if(Wager > Coins)
Wager = Coins;
System.out.println(x + " " + y + " " + z);
if(x == y && x == z)
Coins = Coins + (Wager * 100);
System.out.println("You won " + (Wager * 100) + "!" + " You now have " + Coins + " coins.");
System.out.println("Press 0 to exit, any other number to play that many coins per spin.");
else if((x == y && x != z) || (x != y && x == z) || (x != y && y == z))
Coins = Coins + (Wager * 10);
System.out.println("You won " + (Wager * 10) + "!" + " You now have " + Coins + " coins.");
System.out.println("Press 0 to exit, any other number to play that many coins per spin.");
else ((x != y && x != z) || (x != y && y != z))
Coins = Coins - Wager;
}
while (Wager == 0)
{
System.out.println("You ran out of coins. Thanks for playing.");
}
}
}
你已经使用过python了吗?; D – 2011-02-15 19:45:36