私のプログラムでは、商品の説明、数量、価格をチャートのような形式で表示する必要があります。つまり、商品1の説明は価格と数量に沿ったものになります。これまでのところ、私はインターネット上で見つけたいくつかの方法を試しましたが、成功しませんでした。私はDr. Javaを使用していますので、そのコンパイラと互換性のあるものをお勧めします。 ありがとうございます!ここで文字列をJavaのチャートに書式設定する最も単純ではあるが最も効果的な方法は何ですか?
は、私がこれまで持っているものです。
public static void main(String []args){
Scanner input=new Scanner(System.in);
String sentinel = "End";
String description[] = new String[100];
int quantity[] = new int[100];
double price [] = new double[100];
int i = 0;
// do loop to get input from user until user enters sentinel to terminate data entry
do
{
System.out.println("Enter the Product Description or " + sentinel + " to stop");
description[i] = input.next();
// If user input is not the sentinal then get the quantity and price and increase the index
if (!(description[i].equalsIgnoreCase(sentinel))) {
System.out.println("Enter the Quantity");
quantity[i] = input.nextInt();
System.out.println("Enter the Product Price ");
price[i] = input.nextDouble();
}
i++;
} while (!(description[i-1].equalsIgnoreCase(sentinel)));
// companyArt();
//System.out.print(invoiceDate());
//System.out.println(randNum());
System.out.println("Item Description: ");
System.out.println("-------------------");
for(int a = 0; a <description.length; a++){
if(description[a]!=null){
System.out.println(description[a]);
}
}
System.out.println("-------------------\n");
System.out.println("Quantity:");
System.out.println("-------------------");
for(int b = 0; b <quantity.length; b++){
if(quantity[b]!=0){
System.out.println(quantity[b]);
}
}
System.out.println("-------------------\n");
System.out.println("Price:");
System.out.println("-------------------");
for(int c = 0; c <price.length; c++){
if(price[c]!=0){
System.out.println("$"+price[c]);
}
}
System.out.println("-------------------");
//This is where I multiply the price and quantity together to get the total
double total = 0.0;
for (int j = 0; j < quantity.length; j++){
total += quantity[j] * price[j];
}
if(total != 0){
System.out.println("Total: " + total);
}
}
}
フォーマッタを使用してください:) –
* "Dr.Javaを使用していますので、そのコンパイラと互換性のあるものをお勧めします。" * - コンパイラは無関係です。 –
出力の例を挙げてください。私たちは推測しようとすることができますが、なぜ私たちはそうするべきですか?あなたは私たちの助けが必要なので、あなたが必要とするものに特化してください。そして、あなたは問題を抱えています。 – Andreas