Because you are performing an addition of chars. In Java, when you add chars, they are first converted to integers. In your case, the ASCII code of U is 85 and the code for X is 88.
And you print the sum, which is 173.
If you want to concatenate the chars, you can do, for example:
System.out.print("" + u + 'X');
Now the +
is not a char addition any more, it becomes a String concatenation (because the first parameter ""
is a String).
You could also create the String from its characters:
char[] characters = {u, 'X'};
System.out.print(new String(characters));