ループのみを使用できます。私は配列を使用することができません。ユーザーの入力に基づいて棒グラフを動的に生成する必要があります
私の出力は次のようになります。
How many stores are there?: 5
Enter the total sales for Store 1: 1000
Enter the total sales for Store 2: 1200
Enter the total sales for Store 3: 1800
Enter the total sales for Store 4: 800
Enter the total sales for Store 5: 1900
GRAPH OF TOTAL SALES
(Each * = $100)
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************
しかし、私が得た:ここ
GRAPH OF TOTAL SALES
(Each * = $100)
Store 1 : ********************
Store 2 : ********************
Store 3 : ********************
Store 4 : ********************
Store 5 : ********************
が私のコードです:
私のコードで私は間違っScanner input = new Scanner (System.in);
System.out.println("How many stores are there?: ");
int stores = input.nextInt();
int s = 0;
for(int i = 0; i < stores; i++){
System.out.println("Enter the total sales for Store " + (i + 1) + " : ");
s = input.nextInt();
}
System.out.println("GRAPH OF TOTAL SALES");
System.out.println("(Each * = $100)");
for(int i1 = 0; i1 < stores; i1++) {
System.out.print("Store " + (i1 + 1) + " : ");
for(int t = 0; t <= s/100; t++) {
System.out.print("*");
}
System.out.println();
}
?
ありがとうございます!
内側ループの 's'は常に同じ値です – janos
ストアとは何ですか?コード全体を渡すことはできますか? –
は私のユーザー入力値です – soniya