to test myself in Java, I wrote up a program where I needed to display the contents of double[] measurements
, containing: {8.0, 7.7474, 7.4949, 7.7474, 8.0, 7.7474, 7.4949, 7.7474, 8.0}. A simple enhanced for loop and a println()
seems to work fine, but
for(double measure: measurements)
{
System.out.println(measure + '"');
}
prints out 42, 41.7474, 41.4949, etc. Exactly 34 more than the value of measure
. Changing the code to
for(double measure: measurements)
{
System.out.println(measure + '\"');
}
prints out 18,17.7474, 17.4949, etc. Exactly 10 more than the correct value. It only prints correctly when the println
statement is split into two lines:
System.out.print(measure);
System.out.println("\"");
Why is it that the first two examples add to the value of measure
? I'm fairly new to programming, but it seems to me that they would all have worked because Java uses both apostrophes and quotes to declare a string. Why does splitting it into two statements work correctly while connotating the two add to the value of measure
? Thanks!