Okay, what code have you got so far?
leiger
Junior Poster in Training
91 posts since Jun 2010
Reputation Points: 33
Solved Threads: 6
It won't shows in rows and numbers because you are using System.out.println all the time:
for (String str : values)
{
double str_double = Double.parseDouble(str);
matrix[x][y]=str_double;
System.out.print(matrix[x][y] + " ");
}
You need to print the columns without a new line, and each time you finish a line (exit the inner loop), print a new line as well. Notice that I have changed the locations where you increment x and y - inside the appropriate loops.
while ((line = in.readLine()) != null) //file reading
{
String[] values = line.split(",");
for (String str : values)
{
double str_double = Double.parseDouble(str);
matrix[x][y]=str_double;
System.out.print(matrix[x][y] + " ");
y=y+1; //you have inserted a value to the former y, need to increment
}
x=x+1; // finished the row, need to increment the row number
System.out.println(""); // print a new row.
}
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
It doesn't do it for me, can you please post your code with the changes?
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
It doesn't show that extra line for me - perhaps your are using word wrap and it simply wraps the line?
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
Word wrap means that when a line is full, it will continue automatically to a new line. Assuming that you are using windows, copy all of the output from the program into notepad. Then go to Format and make sure that Word Wrap is not checked - still see those empty lines?
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
Then redirect the output to a file (at the end of you command type "> fileName.txt")
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55
As far as I can tell it is the word wrap in the command line that causes all those phantom lines. The lines with the minus signs are longer than the ones without, which can explain the fact that the new line appears every second line. You can always try a smaller input data file if you really want to :).
apines
Practically a Master Poster
633 posts since Apr 2007
Reputation Points: 129
Solved Threads: 55