我的代码没有停止我使用do while循环的迭代,我想只在secondThrow与firstThrow不同而不是数字7时进行迭代?????帮助
import java.util.Scanner;
public class Craps_callee
{
private Die die1;
private Die die2;
public Craps_callee() //
{
die1 = new Die ();
die2 = new Die ();
}
private void rollDice()
{
die1.roll();
die2.roll();
}
private int getSum()
{
int sum = die1.getNumber()+die2.getNumber();
return sum;
}
public void playRound()
{
rollDice();
int firstThrow = getSum();
int secondThrow = getSum();
//for (int i; i )
if(firstThrow == 7 || firstThrow == 11)
{
System.out.println("You rolled a " +firstThrow+ " You Win Congratulations!");
}
else if (firstThrow == 2 || firstThrow == 3 || firstThrow == 12)
{
System.out.println("You rolled a "+firstThrow+" You Lose! ");
}
else
{
System.out.println("You rolled a: "+firstThrow);
System.out.println(" !! Establish Point !!");
System.out.println(" you need to roll another "+firstThrow+" to win before 7 is rolled");
do
{
rollDice();
secondThrow = getSum();
System.out.println("SeconndThrow is: "+secondThrow);
System.out.println("FirstThrow is: "+firstThrow);
if (secondThrow == firstThrow)
{
System.out.println("You rolled a " +secondThrow+ " Twice. You Win Congratulations!");
}
else if (secondThrow == 7)
{
System.out.println("You rolled a 7 You Lose! ");
}
}
while (secondThrow != firstThrow || secondThrow != 7);
}
}
public static void main(String[] args)
{
String prompt_from_user;
Scanner scan = new Scanner(System.in);
System.out.println("Input the amount of "+scan);
prompt_from_user = scan.nextLine();
if (prompt_from_user == "YES" || prompt_from_user == "yes");
{
}
这是错误的部分
do
{
rollDice();
secondThrow = getSum();
System.out.println("SeconndThrow is: "+secondThrow);
System.out.println("FirstThrow is: "+firstThrow);
if (secondThrow == firstThrow)
{
System.out.println("You rolled a " +secondThrow+ " Twice. You Win Congratulations!");
}
else if (secondThrow == 7)
{
System.out.println("You rolled a 7 You Lose! ");
}
}
while (secondThrow != firstThrow || secondThrow != 7);
答案 0 :(得分:1)
我只想在>时进行迭代secondThrow与>不同> firstThrow而不是7号
阅读句子然后意识到你的条件应该实现AND而不是OR