java - Arrays are being filled with null instead of names and 0 instead of numbers -


I have to fill two different arrays with a text file and the name from the related account balance. The file looks like this

  10 Helen 1000 Jordan 755 EV 2500 Ken 80 Andrew 99 9 17 17 Admin Amy 12 Shaun 98 Patrick 7 Joy 14   

Where is the number of accounts

  import java.util *; Import java.io * *; Import java.util.Arrays; Public square bank countmen {public static zero main (string [] args) filenotfound exception {scanner infix = faucet; {InFile = Try New Scanner (New File ("account.txt")); ; } Hold (FileNotFoundException e) {System.out.println ("File not found!"); System.exit (0); } Int count = 0; Int accounts = inFile.nextInt (); String [] name = new string [accounts]; Int [] Balance = new int [accounts]; While (inFile.hasNextInt ()) {inFile.next (); Name [count] = inFile.next (); InFile.nextInt (); Balance [count] = inFile.nextInt (); Count ++; } System.out.println (Arrays.toString (name)); Println (Arrays.toString (balance)); }}    

Your loop is poorly defined.

You see to it that the next integer is instead of the next token, and consuming lines that you do not intend.

Instead, try this as a loop:

  (InFile.hasNext ()) {names [count] = inFile.next (); Balance [count] = inFile.nextInt (); Count ++; }    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -