如何使用多种方法一起添加数组
public void inputArray() {
Scanner keyboard = new Scanner (System.in);
System.out.println("Please enter the number of invoices: ");
numInvoices = keyboard.nextInt();
Invoices = new Invoice[numInvoices];
int BillTotal = 0;
for(int i = 0; i < numInvoices; i++){
Invoices[i] = new Invoice();
Invoices[i].setCompanyNameFromUser();
Invoices[i].setBillAmountFromUser();
Invoices[i].SetDateFromUser();
BillTotal = BillTotal + Invoices[i].setBillAmountFromUser;
在这种情况下,我想在setBillAmountFromUser方法中添加用户输入的值。
答案 0 :(得分:0)
此程序块可以帮助您
public void inputArray()
{
Scanner keyboard = new Scanner (System.in);
System.out.println("Please enter the number of invoices: ");
int numInvoices = keyboard.nextInt();
int BillTotal=0;
Invoice Invoices[numInVoices];
for(int i=0;i<numInVoices;i++)
{
Invoices[i]=new Invoices();/*Your Code*/
BillTotal+=Invoices[i].setBillAmountFromUser();
}
System.out.println("BillTotal="+BillTotal);
}
public int setBillAmountFromUser()/*Example Code block/*
{
/*your code */
return 5;//Example Return value
}