我正在编写一个程序,需要用户输入并根据他们的答案给他们一个不同的答案。如何使用用户使用if - else语句输入的字符串?字符串如果 - 在Java中的其他语句
我有这个至今:
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
class t1_lesson07_template{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.print("Hello, welcome to the companion planting guide. ");
System.out.print("Lets get started! To begin, just input the desired plant in the box to learn what plants to grow with it!");
String plant = scan.nextLine();
if (plant == "Asparagus") {
System.out.print("Tomatoes, parsley, and basil.");
}
}
}
我想知道有关语法在这种情况下,if语句。
你在网上查找“if语法java”吗?为什么不尝试编译这个? –
结帐这个真棒帖子 http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java –