【发布时间】:2013-11-07 02:55:41
【问题描述】:
我正在制作一个程序,当用户输入一种心情时,它会根据它输出一个报价。我需要告诉程序if the user is happy, then output this text 问题是,我不知道如何让程序识别输入并基于它输出文本...这是我到目前为止的代码。
import java.util.Scanner;
public class modd {
public static void main(String arrgs[]) {
System.out.println("Enter your mood:");
Scanner sc = new Scanner(System.in);
String mood = sc.nextLine();
if (sc = happy) {
System.out.println("test");
if (sc = sad) {
System.out.println("I am sad");
}
}
}
}
【问题讨论】:
-
我先看看
Strings 上的Java Tutorial -
了解如何比较字符串。
switch也可能有所帮助。您的输入也是mood(不是sc)。