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.
- 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?