//different types of items purchased
System.out.print("How many different types of items are being purchased? ");
ArraySize = input.nextInt();
input.nextLine();
//arrays - being defined after ArraySize
String[] item = new String[ArraySize]; //each item
int[] itemsPurchased = new int[ArraySize]; //item purchased
double[] price = new double[ArraySize]; //price for each 'line' on the receipt
double[] itemPrice = new double[ArraySize]; //price of item purchased
for (int i=0; i<ArraySize; i++){ //i = variable element counter
//name of item purchased
System.out.print("Item purchased: ");
item[i] = input.nextLine();
//number of items purchased
System.out.print("Quantity: ");
itemsPurchased[i] = input.nextInt();
input.nextLine();
//determines price of item based on what was purchased
if (item.equals("Shoes") || item.equals("shoes") || item.equals("SHOES"))
itemPrice[i] = 50.00;
if (item.equals("T-Shirt") || item.equals("t-shirt") || (item.equals("T-SHIRT")))
itemPrice[i] = 40.00;
if (item.equals("Shorts") || item.equals("shorts") || item.equals("SHORTS"))
itemPrice[i] = 75.00;
if (item.equals("Cap") || item.equals("cap") || item.equals("CAP"))
itemPrice[i] = 20.00;
if (item.equals("Jacket") || item.equals("jacket") || item.equals("JACKET"))
itemPrice[i] = 100.00;
//adds item and item amount
price[i] += (itemsPurchased[i] * itemPrice[i]);
}//end for
我試圖做出看起來像添加數組元素
項目----------數量收據線-------- ---成本
項目----------數量-----------成本
項目----------數量 - ---------成本
但我坐下來保持成本(非常最後一行我鏈接)的行不保留任何東西后的第一個元素。 我只鏈接了我認爲相關的東西,如果需要,我可以給出剩下的代碼。
你可以用'item.equalsIgnoreCase(「AnYKIndOfStRiNg )「'不要使用那3個等號。 – 2012-07-11 02:11:16
謝謝! :) – user1462585 2012-07-11 02:16:59