Need major help on FileReader/Array/Matrix Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prime8
    New Member
    • Feb 2008
    • 1

    Need major help on FileReader/Array/Matrix Program

    I've been researching so much about arrays and matrices and such, but it hasn't helped me at all on my program. Everything is either over my head or doesn't help with the specific program I have to code. All I've been able to do so far is to get the file read in.

    Program: Write a code that will read in a text file (which contains a list of words and their definitions, separated by a hyphen). The data read in will be stored into an array. Then store the array into a matrix, and output the matrix. Be sure to print out a hyphen to separate the words and their definitions.

    Code:
    import java.io.*;
    import java.util.*;
    
    public class oops
    {
    	public static void main (String args[]) throws IOException
    	{
    		String[] y = new String[2];
    		Scanner in = new Scanner (new FileReader ("oopswords.txt"));
    		while (in.hasNext())
    		{
    			String text = null;
    			text = in.nextLine();
    			y = text.split("-");
    		}
    		
    	}
    }
    How would I go about putting the data read in into an array? I'm not sure if the y=text.split("-") is correct, or at least in the right spot. Do I have to make a for loop to input the data into an array, and if so, does the for loop go inside or out of the while loop? I'm assuming that two arrays will be used: one for the words and one for the definitions, but again, I'm not that certain. Then how do I write the array(s) into a matrix to print it out?
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5264478

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Prime8
      ...
      How would I go about putting the data read in into an array? ...
      The split method actually returns an array ..

      Comment

      Working...