【发布时间】:2014-02-09 15:55:14
【问题描述】:
我正在编写一个程序,该程序接受用户输入,并根据他们的回答给出不同的答案。如何使用用户通过 if - else 语句输入的字符串?
到目前为止我有这个:
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 syntax java”?为什么不尝试编译呢?
-
查看这篇精彩的帖子stackoverflow.com/questions/513832/…
标签: java if-statement syntax statements