2016-01-09 37 views
-1

我剛剛開始使用Java昨天。我試過研究,但沒有找到任何我可以利用的東西。問題是不管我輸入什麼輸入,程序總是輸出「Hell」和「Hello fmdas」。我想我應該寫if (BetOrPlay != "Bet");線作爲else if (BetOrPlay != "Bet"); 但該計劃不允許我這樣做。在java中我可能犯了一些明顯的錯誤,我找不到(java)

import java.util.Scanner; 

public class MoneyMaker 
{ 

    static Scanner Choice = new Scanner (System.in); 


    public static void main(String[] args) 
    { 
     System.out.println("Do you want to bet your coins or earn more by playing this game?"); 
     try 
     { 

      if (Choice.hasNextLine()) 
      { 
       String BetOrPlay = Choice.nextLine(); 
       if (BetOrPlay == "Bet"); 
       { 
        System.out.println("Hell"); 
       } 
       if (BetOrPlay != "Bet"); 
       { 
        System.out.println("Hello fmdas"); 
       }  
      } 
     } 
     finally 
     { 
      Choice.close(); 
     } 
    } 
} 
+1

使用.equals()比較字符串作爲標記的重複顯示。另外,在if語句之後加上分號(;),會使if語句無用。 – user3284549

回答

0

你實際上沒有在if塊下做任何事情。

if (BetOrPlay == "Bet"); //remove ; here 
    if (BetOrPlay != "Bet"); //remove ; here 
相關問題