Java代码无法编译

时间:2015-10-06 08:02:21

标签: java syntax

我有这段代码但是当我尝试编译它时,我只是收到错误。谁能发现sytnax错误,或者我做错了什么?

public double getTotalBalance(ArrayList<String> accounts)
{
double sum = 0;
while (studentNames.size() > 0)
{
BankAccount account = accounts.remove(O); // Not recommended
sum = sum + account.getBalance();
}
return sum;
}

2 个答案:

答案 0 :(得分:1)

Maybe the right code is:

public double getTotalBalance(ArrayList<BankAccount> accounts)
{
    double sum = 0;
    while (accounts.size() > 0)
    {
         BankAccount account = accounts.remove(0); // Not recommended
         sum = sum + account.getBalance();
    }
    return sum;
}

答案 1 :(得分:0)

accounts.remove(O)似乎有问题。当您传递ArrayList<String>个帐户时,帐户Arraylist仅包含strings?。