Hi,
i've been trying to solve some java questions, to prepare for a test. I came across a question and im not sure if my answer is correct or not. Is it ok if you guys check it for me and give me your feedback?
this is the question:
What does the following code do with the array list accounts.
This is the answer i came up with:
the for loop will check “for each BankAccount a in accounts.” Then it will check if (a.getAccountNu mber() is equal to accountNumber) then it return the value of that account.
so what do you think?
thanks!!
i've been trying to solve some java questions, to prepare for a test. I came across a question and im not sure if my answer is correct or not. Is it ok if you guys check it for me and give me your feedback?
this is the question:
What does the following code do with the array list accounts.
Code:
public class Bank { public BankAccount doSomething(int accountNumber) { for (BankAccount a : accounts) { if (a.getAccountNumber() == accountNumber) return a; } return null; } . . . }
the for loop will check “for each BankAccount a in accounts.” Then it will check if (a.getAccountNu mber() is equal to accountNumber) then it return the value of that account.
so what do you think?
thanks!!
Comment