When writing my code to schedule a computer in which we see the compatibility of an array of four objects, my code prints strangely. (Eclipse at first did not inform me of the error / warning).
code:
System.out.print("Fit between " + profile1.getTitle() + " and " + profile2.getTitle() + ": \n " + + '\t' + profile1.fitValue(profile2) + '\n');
When I tried to print, they looked like this:
Go between Elizabeth Bennett and Elizabeth Bennett: 90.0
Set between Elizabeth Bennett and Fitzwilliam Darcy: 90.55
Bout between Elizabeth Bennett and Romeo Montague: 90.3
Approach between Elizabeth Bennett and Juliet Capulet: 90.0
.................................................. ..... and so on.
In front of my numbers appeared "9".
I found the problem later: I had two concatenating operators ("+") after my "\ n". Therefore, I changed my code by deleting the extraneous "+".
New code:
System.out.print("Fit between " + profile1.getTitle() + " and " + profile2.getTitle() + ": \n " + '\t' + profile1.fitValue(profile2) + '\n');
New correct start:
Go between Elizabeth Bennett and Elizabeth Bennett: 0.0
Set between Elizabeth Bennett and Fitzwilliam Darcy: 0.55
Bout between Elizabeth Bennett and Romeo Montague: 0.3
Go between Elizabeth Bennett and Juliet Capulet: 0.0
.............................................. and so on. d.
Although I gratefully found my problem, I want to know what exactly causes this. Is there any shorthand for the eclipse that leads to the appearance of "9"? Or is it due to some kind of eclipse error? I am still new to java, so I cannot draw a convincing conclusion.
I tried modifying my code a bit to see how Eclipse would react (I removed the space between my original “++”):
System.out.print("Fit between " + profile1.getTitle() + " and " + profile2.getTitle() + ": \n " ++ '\t' + profile1.fitValue(profile2) + '\n');
Eclipse gave me this warning:
Several markers on this line
This makes sense because ++ itself is a kind operator. Interestingly, however, if I put a space between “++”, then the warning disappears.
I did not paste all my code for readability, but if necessary, I can edit and add it. Some clarification on this would be helpful. Thanks.