사용자 입력을받는 프로그램을 작성 중이며 답변에 따라 다른 대답을 제공합니다. 사용자가 입력 한 문자열을 if - else 문과 함께 사용하려면 어떻게해야합니까?Java의 If - Else 문에 포함 된 문자열
나는 지금까지이 :이 경우에 if 문에 대한 구문에 대해 궁금
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.");
}
}
}
.
인터넷에서 "syntax java"를 찾으려고 했습니까? 왜 이것을 컴파일하려고하지 않습니까? –
체크 아웃이 멋진 게시물 http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java –