好的,我正在尝试做这个简单的事情,但它不起作用。我是 Java 初学者,需要一些帮助。每次我运行下面的代码时,我都会得到输出That is not a valid option。我究竟做错了什么?
package test;
import java.util.Scanner;
public class options {
public void options() {
Scanner scnr = new Scanner(System.in);
String slctn;
System.out.println("What would you like to do?");
System.out.println("a) Travel the expedition");
System.out.println("b) Learn more about the expedition");
slctn = scnr.nextLine();
if (slctn == "a"){
travel exeTravel = new travel();
exeTravel.travel();
}else if (slctn=="b"){
learn exeLearn = new learn();
exeLearn.learn();
}else{
System.out.println("That is not a valid option");
}
}
}