2017-06-17 51 views
-1

你能幫我找出我錯過了下面的代碼嗎?我正在使用Eclipse。字符串和||陳述

Scanner scanner = new Scanner(System.in); 
    String input = scanner.nextLine(); 
    { 
    if (input.equalsIgnoreCase(("front door") || ("front") || ("basement") || ("basement entrance"))) 
     if (input.equalsIgnoreCase(("front door") || ("front"))   
      System.out.println("Maggie went to the side of the home and open the basement door. As the door opened, she could smell the dust from inside.");  
     else  
      if ((input.equalsIgnoreCase("basement") || ("basement entrance"))) 
       System.out.println("Maggie walks up the steps and slowly opens the front door.");    
    else  
     System.out.println("That is not a correct answer"); 
+1

使用'{}'你IFS是明確其是否具有其他.. –

+1

上的兩邊的操作數||運算符必須具有布爾值true/false。他們不是更早的函數調用的附加可能性。 –

回答

0

我認爲有幾個誤區: 1.如果-else邏輯:

a)if(input.equalsIgnoreCase((「front door」)||(「front」)|| (「basement」)||(「basement entrance」))) if(input.equalsIgnoreCase((「front門「)||(」前「))

這是什麼意思?其次如果是多餘的。 二)

其他
IF((input.equalsIgnoreCase( 「地下室」)||( 「地下室入口」)))

這部分是無法訪問的,因爲如果將其覆蓋。

  1. if(condition)中的語法錯誤。

假設它應該llke

String input = scanner.nextLine(); 
     { 
      input = input.toLowerCase(); 

     if (input.equals("front door") || input.equals("front"))    
       System.out.println("Maggie went to the side of the home and open the basement door. As the door opened, she could smell the dust from inside.");  
     else if (input.equals("basement") || input.equals("basement entrance")) 
        System.out.println("Maggie walks up the steps and slowly opens the front door.");    
     else  
      System.out.println("That is not a correct answer"); 
+1

把括號放在'if'身體周圍! –

0
那不是你如何使用邏輯或操作員

,你必須做一些像

if (input.equalsIgnoreCase("front door") || input.equalsIgnoreCase("front") || 
    input.equalsIgnoreCase("basement") || input.equalsIgnoreCase("basement entrance")) { 
    ... 
}