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