我正在尝试编写代码,以便用户输入eventType
的值时,它在我的最终声明中会打印出三明治,炸鸡或巴马干酪,但会出现错误。
import java.util.Scanner;
public class eating {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Is this a casual, semi-formal, or formal event?");
String eventType = scanner.next();
// String[] eventType = { "casual", "semi-formal", "formal" };
// String[] mealSuggestion = { "sandwiches", "fried chicken", "chicken parmesan"
// };
if (eventType == "casual")
System.out.print("sandwich");
if (eventType == "semi-formal")
System.out.print("chicken");
if (eventType == "formal")
System.out.print("chicken parmesan");
System.out.println("How many people are in your party?");
int partySize = scanner.nextInt();
System.out.print("Since you are hosting a " + eventType);
System.out.print(" event for " + partySize);
System.out.print(" participants, you should serve " + eventType);
String[] prepSuggestion = { "in the microwave", "in your kitchen", "by a caterer" };
System.out.print(" prepared" + prepSuggestion);
String result;
}
}
这是当前打印出的内容:
Since you are hosting a casual event for 30 participants, you should servecasual prepared[Ljava.lang.String;@4c203ea1