Note that there are some explanatory texts on larger screens.

plurals
  1. POjava read input from file with multiple data types of varying lengths
    primarykey
    data
    text
    <p>I'm trying to read from a file containing names and doubles, this would be easy if it was first name, last name then the doubles, but some of the lines have a middle initial and some have just one name. <br><strong>Like this:</strong> <br>Hancock John 40.00 9.75 <br>Light Karen L 40.00 9.60 <br>Bob 12.02 42.90 <br>and so on I'm putting the names into a string array and the numbers into a 2d array. So how would I separate those data types? EDIT: I was trying this at first </p> <pre><code> import java.io.*; import java.text.*; import java.util.*; public class JEdwards11 { public static void main(String[] args) throws Exception { PrintWriter outFile = new PrintWriter("H:/Java/program11.out"); String filename = "H:/Java/program11.dat", line, fullname; StringTokenizer st; Scanner inFile = new Scanner(new FileReader(filename)); int ctr = 0, i = 0, k = 0; String [] names = new String [30];//print vertically double [][] money = new double [7][30];//short across, long down //hours worked, hourly rate, gross pay, net pay, fed, state, union //while(inFile.hasNext()) for(i=0; i&lt; names.length; i++) { if(inFile.hasNextDouble()) {money[1][i] = inFile.nextDouble(); money[2][i] = inFile.nextDouble();} else names[i] = inFile.next(); } /*while(inFile.hasNext()) {line = inFile.nextLine(); st = new StringTokenizer(line); names[i]=st.nextString; money[1][i] = st.nextDouble(); money[2][i] = st.nextDouble();*/ for(i=0;i&lt;names.length;i++) for(i=0; i&lt;names.length; i++) System.out.println("name = " + names[i] +" money1 = "+money[1][i] +" money2= "+money[2][i]); inFile.close(); outFile.close(); } } </code></pre> <p>which did not work at all. Since then I've searching Google and re-reading my java book. Sorry for the formatting, it's not being cut/paste friendly and last time I hit enter it posted before I was ready :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload