所以我創建了一個發票生成器,我需要用戶先說出他們將輸入多少物品,然後詢問物品描述(字符串),金額(int)和價格(int)。我無法爲這些信息創建數組。到目前爲止,我只創建了像這裏它們的方法:如何創建一個獲取用戶輸入的數組系統?
public static int itemDescription(){
Scanner input=new Scanner(System.in);
String descr = input.nextInt();
return(descr);
}
public static int quantitySold(){
Scanner input=new Scanner(System.in);
int quansold = input.nextInt();
return(quansold);
}
public static int unitPrice(){
Scanner input=new Scanner(System.in);
System.out.println("Unit Price:");
int price = input.nextInt();
return(price);
}
但是,如果用戶有一個以上的項目投入,那麼我就需要使用數組,因爲這些將不能夠存儲超過一件數據的。 (我使他們分開的方法,因爲我將需要單獨的信息後來分別計算他們的稅收。)
我怎麼能把這些輸入功能變成數組?
謝謝你提前