宿題で困っています。基本的なロジックはダウンしていますが、めちゃくちゃです。目的は、ユーザーが入力した買い物リストからレシートを作成することです。たとえば、ユーザーは次のように入力します。
Apples
OraNgeS // also it's not case sensitive
Oranges
Bananas
!checkout //this is to indicate the list is over
出力:
Apples x1
Oranges x2
Bananas x1
私は立ち往生しています。これまでの私のコード:
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.printf("Enter the items you wish to buy:");
String[] input = new String [keyboard.nextLine()];
keyboard.nextLine(); //consuming the <enter> from input above
for (int i = 0; i < input.length; i++) {
input[i] = keyboard.nextLine();
}
System.out.printf("\nYour input:\n");
for (String s : input) {
System.out.println(s);
}
}
最終的には if ステートメントを追加する必要があることはわかっているので、「!checkout」と入力するとリストが終了します。しかし、私はまだこれを乗り越えることができません。
ヒントやアドバイスはありますか?