<分区>
我正在尝试用 Java 创建一个程序,它允许用户从包含在 String 数组中的咖啡列表中挑选并继续,但它没有通过检查并打印出 else 语句。
相关代码如下:
Scanner scan = new Scanner(System.in);
String[] flavors = {"Black", "French Vanilla", "Hazelnut", "Mango", "Cherokee", "anarcho-syndicalism", "Otis" };
...
System.out.println("Today we have " + Arrays.toString(flavors));
System.out.println("Please enter the name of the coffee you would like exactly as shown above: ");
String coffee = scan.next();
...
for (int i = 0; i < flavors.length; i++) {
if (coffee == flavors[i]) {
String selection = flavors[i];
虽然此处未显示,但我相信稍后在程序中的所有内容都已正确格式化。有什么想法吗?