java - Searching through arraylists for the largest number -
So I'm currently creating a code that searches through the simple list and prints the largest one This code prompts the user for the bank account name and how much money the account is. At present I do not know how to find the largest number through simple list, I have not attended to the problem. I do not even know how to compare the maximum balance. Any help is appreciated, thanks.
import java.io. *; Import java.util. *; Import java.text *; Public square Project43Tester {public static zero main (string array []) {NumberFormat formatter = NumberFormat.getNumberInstance (); Formatter.setMinimumFractionDigits (2); Formatter.setMaximumFractionDigits (2); String name; ArrayList & lt; String & gt; AryLst = new ArrayList & lt; String & gt; (); Doing {scanner KBRDER = new scanner (System.in); System.out.print ("Please enter the name whose name is E. (To terminate \" Exit \ ")"); Name = kbReader.nextLine (); If (! Name.equalsIgnoreCase ("EXIT") {System.out.print ("Please enter the deposit amount."); Double zodiac = kbReader.nextDouble (); System.out.println (""); ArrayList & lt; String & gt; Bank account = new & lt; String & gt; array list(); AryLst.add (BankAccount); }} While (! Name.equalsIgnoreCase ("EXIT")); Search the Erril and search the name and the largest bank account bank account BA = // Maximum Account Double Max Balance = BALLAS; String maxName = ba.name; (Int j = 1; j & lt; aryLst.size (); j ++) {? ? Step through the remaining items and decide which is the largest balance (compare each balance to maximum balance)? } System.out.println (""); System.out.println ("The largest balance account" + comes under + maximum name + ""); System.out.println ("The amount that is included in the account $" + formatter.format (maxBalance) + "."); }}
You have to cross the ArrayList. During the ArrayList's traversal, set the first element to the maximum and compare it with it. If it is high, then set the new element as the maximum element.
Comments
Post a Comment