2015-11-20 67 views
0

我似乎得不到這回來的結果,它總是崩潰。我知道如何阻止它崩潰,只是沒有得到它。 Eclipse告訴我userIn從不關閉。如果你能告訴我我出錯的地方,將不勝感激。使用用戶輸入

import java.util.Scanner; 
public class Translator { 

    public static void main(String[] args){ 

     Scanner userIn = new Scanner(System.in); 

     System.out.println("Word?"); 

     String word; 

     word = userIn.nextLine(); 

     if(word == "Pollo"){ 

      System.out.print("Pollo - Chicken"); 

     }if(word == "Bien"){ 

      System.out.print("Bien - Good"); 

     }if(word == "Alto"){ 

      System.out.print("Alto - Tall"); 

     } 

    }  

} 

回答

0

您應該使用word.equals("Pollo")而不是word=="Pollo"。這與其他人一樣。這是因爲你想比較單詞而不是對象。

例子:if(word == "Pollo")變化if(word.equals("Pollo"))

+0

*您當前比較的對象,而不是字 –