System.out.println(max.getAccountNumber().\"\"+max.get Balance()]; System.out.pr
ID: 3831676 • Letter: S
Question
System.out.println(max.getAccountNumber().""+max.get Balance()]; System.out.println(min.getBalance(). ""+min. getBalance()]; } } Consider the algorithm that we used for determining the maximum value in an array list. We set largest Yet to the starting element, which meant that we were no longer able to use the "for each" loop. An alternate approach is to initialize largest Yet with null, then loop throughout all elements, of course, inside the loop you need to test whether largestYet is still null. Modify the loop that finds the bank account with the largest balance. using this technique. Is this approach more or less efficient than the one used in the text? BankAccount largest Yet accounts get(); for (int i=1.i largestYet.getBalance ()) largestYet=a; } return largestYet; Rewrite the following loop without using the "for each" construct. Here, data is an array of double values, for (x-data) if(x==target) return true; Consider an enhancement of the Die class with a static field: public class Diel public Die [int s] (..) public int cast ()(,...) private int sides: private static Random generator new Random () }Explanation / Answer
Solution:
The largestYet can be extracted using the while loop as well:
largestYet= NULL; // To set the largestYet to NULL
while(accounts.size()--)
{
if(a.getBalance()> largestYet.getBalance())
largestYet= a;
}
Instead of for each construct we can use while loop here which goes as shown below:
while(x.data!=NULL)
{
if(x==target)
return true;
x++;
}
The above loop statement will loop through the each element in the x
I hope this helps. Don't forget to give a thumbs up if you like this.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.