2015-12-03 122 views
-2

如何用幾種方法一起如何增加數組值

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

該程序塊可以幫助你

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 
    }