我的代碼行如下。我試圖讓星號在商店旁邊打印,並與之相關聯。眼下,例如,如果我輸入200店1,它會輸出:如何在同一行上打印一行文字作爲循環輸出
Store 1:
**
,但我想它輸出:
Store 1: **
我會怎麼做呢?
int store1;
System.out.print("Enter today's sales for store 1 in dollars: $");
store1 = keyboard.nextInt();
int store2;
System.out.print("Enter today's sales for store 2 in dollars: $");
store2 = keyboard.nextInt();
int store3;
System.out.print("Enter today's sales for store 3 in dollars: $");
store3 = keyboard.nextInt();
int store4;
System.out.print("Enter today's sales for store 4 in dollars: $");
store4 = keyboard.nextInt();
int store5;
System.out.print("Enter today's sales for store 5 in dollars: $");
store5 = keyboard.nextInt();
System.out.println("SALES BAR CHART");
System.out.println("Store 1:");
for (int a = 0; a <= store1; a += 100)
{
System.out.print("*");
}
System.out.print("\n");
System.out.println("Store 2:");
for (int b = 0; b <= store2; b += 100)
{
System.out.print("*");
}
System.out.print("\n");
System.out.println("Store 3:");
for (int c = 0; c <= store3; c += 100)
{
System.out.print("*");
}
System.out.print("\n");
System.out.println("Store 4:");
for (int d = 0; d <= store4; d += 100)
{
System.out.print("*");
}
System.out.print("\n");
System.out.println("Store 5:");
for (int e = 0; e <= store5; e += 100)
{
System.out.print("*");
}
System.out.print("\n");
System.out.print("Each * represents $100");
嘗試'的System.out.println();是System.out.print( 「存儲1:」);'代替'系統.out.println(「Store 1:」);' – Gangaraju