1
我想创建一个Java程序,它允许用户从一个字符串数组中包含的咖啡列表中选择并继续,但它没有通过检查并打印出来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];
虽然这里没有显示,我相信一切都正确格式化以后的该程序。有任何想法吗?
这似乎得到它。谢谢,亚萨! – 2014-12-13 15:51:03