こんにちは私はユーザーに単語を入力させて価格を教える2次元配列を作成しました。どのように私はforループを使用してこのプログラムを改善することができますか?今後のお返事ありがとうございます。悪い編集をおかけして申し訳ありません。2次元配列でこれを改善する方法
String[][] the ={
{"Best Health Basic","R450.00"},
{"Best Health Basic Plus","R575.00"},
{"Best Health Premium","700.00"},
{"Best Health Premium Plus","950.00"}};
String INPUT = JOptionPane.showInputDialog("Enter one of the following\nBest Health Basic\nBest Health Basic Plus\nBest Health Premium\nBest Health Premium Plus");
if (the[0][0].equalsIgnoreCase(INPUT)) {
System.out.println("found it " + the[0][1]);
return;
}
if (the[1][0].equalsIgnoreCase(INPUT)) {
System.out.println("found it " + the[1][1]);
return;
}
if (the[2][0].equalsIgnoreCase(INPUT)) {
System.out.println("found it " + the[2][1]);
return;
}
if (the[3][0].equalsIgnoreCase(INPUT)) {
System.out.println("found it " + the[3][1]);
return;
}
ありがとうございました! –
ループを中断するために 'return'を使うことはお勧めしません。 '休憩 'はもっと理にかなっています。 –
コンサインこの質問に答えるために、有益な答えの1つをマークしてください。 –