What does the following program snippet print?
System.out.println ( 'a' + '\r' );
System.out.println ( 'a' + "\r" );
System.out.println ( "a" + '\r' );
System.out.println ( "a" + "\r" );
I'm rather new to Java myself so I welcome these brain teasers. Having made the
mistake a few times to use 'test' instead of "test" when I needed a String its
my idea that it will do something funny with the '' encapseling.
cr/lf = 0d0a, but I'm not too sure what the ascii value of 'a' is. So my idea
is that it won't pick up the 'a' and '\r' as being Strings (perhaps a char) and
as such add them all up. No idea what the end result may be, probably an ASCII
value (if my theory is correct then it can't turn into high ascii) so I think
it'll start to print a letter in the range of ASCII value 70 - 100 (decimal).
Next the "" does denote a String but iirc \r doesn't resemble a cr/lf, thats
what \n does in a String. My guess is that it will simply print a character
here as well without anything special about it.
Since the 3rd line is basicly the same as the 2nd the same theory applies.
Last you have 2 Strings but since I'm positive \n to be cr/lr I think it'll
just print the 'a' as well.
I can't go for the bonus I guess since I'm using Netbeans. I haven't done much
with something specific like this on stdout so I'll have to guess as well; I
hope it behaves in the same was as the program does on the console.
Right, and now to test this later on
Thanks for the teaser, its a nice one IMO.