Reputation: 3
I'm working on a java program using arrays and loops to create a table, however when the values print they are followed by "java.io.PrintStream@1909752" repeating over and over a number of times
The chunk of code causing the error is as follows, more specifically the "row +=" sections. Any help for how to get rid of the repeated part at the end would be appreciated.
for ( int i = starting; i <= ending; i+= 1){
row += System.out.format("%6d" + ": ", i);
for ( int j = 0; j <= 11; j+=1){
double answer = i*octaveArray[j];
row += System.out.format("%.0f ", answer );
}
System.out.printf(row);
System.out.println("");
}
Upvotes: 0
Views: 978
Reputation: 34796
From the documentation of PrintStream#format()
:
Writes a formatted string to this output stream using the specified format string and arguments.
That means that PrintStream#format()
will write the values to the output stream but you then append its toString
representation which looks like java.io.PrintStream@1909752
to the row
variable which you then print out to the same output stream.
You should use String.format()
instead if you wish to append the formatted result to a String
variable.
Upvotes: 3