2017-03-09 74 views
0

我的代碼並沒有停止迭代,我使用while 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

添加一個'break;'打印出來後,你贏了 –

+0

我到底在哪裏放? – Bando

+0

歡迎來到Stack Overflow!它看起來像你需要學習使用調試器。請幫助一些[互補調試技術](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之後仍然有問題,請隨時返回更多詳情。 –

回答

1

我想,當> secondThrow是不一樣>>的firstThrow而不是7號

只迭代

閱讀句子,然後意識到你的情況應該實現AND而不是OR或

相關問題