對於這個大膽的問題,您好,非常抱歉,但我不知道如何解決我在代碼行24和30上的需求。也即時獲得第33和第22行的錯誤消息,所以如果你能解決這些問題,那將是非常棒的。無法在if語句中使用字符串
import java.util.Scanner;
public class CheckOrder {
public static Scanner userInput = new Scanner(System.in);
public static Scanner userInputStarters = new Scanner(System.in);
public static String menu;
public static String check;
public static String TheRestroom = "The Restroom";
public static String Restroom = "Restroom";
public static String Eat = "Eat";
public static String ToEat = "To Eat";
public static String restOrEat;
public static void main(String[] args) {
System.out.print("Hello and Welcome to the SOMETHING restaurant. Would you like to eat or use the restroom?");
public static restOrEat = userInput.NextInt();
if (restOrEat.equalsIgnoreCase(TheRestroom || Restroom)) {
System.out.println("Please go ahead to the restroom, it's over there.");
System.exit(1);
}
if (restOrEat.equalsIgnoreCase(Eat || ToEat)) {
System.out.print("What would you like to eat for starters? Press 1 for Cheese & Bacon, 2 for Sald (With options) and 3 for noodles");
public static String starter = userInputStarters;
}
}
}
請發佈一個MCCVE(如[MCVE],但可編譯)。一些閱讀:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#equalsIgnoreCase-java.lang.String- – 2017-07-18 11:32:15
你嘗試了一個'sys.out'並檢查。用戶輸入可能需要'trim'。 – Mritunjay
你不應該一次檢查'equalsIgnoreCase'。 – soorapadman