I cant print two char in one system.out.print code as it is shown in below. I would like to know how java works in that case since it is summing up ASCII conversions of these chars.
System.out.println('a'+'b');
I cant print two char in one system.out.print code as it is shown in below. I would like to know how java works in that case since it is summing up ASCII conversions of these chars.
System.out.println('a'+'b');
This is Java, not JavaScript.
In Java, the single quote is reserved for char data. You must use the double quote for a String value.
As stated in the @Sean Bright comment, char + char is math, not string concatenation.
There are many ways to output two char values. Here is an example of one such way:
final String output;
output = String.format("%c %c\n", 'a', 'b');
System.out.println(output);
The output of the last one is 195, because you are doing an addition of char values in the ASCII table (97+98) . you first sum all the values as explained before, then convert it to a String adding "" to the sum of the ASCII values of the chars. However, the println method expect a Strin Y