-1

Here is a program that demonstrates char variables:

// Demonstrate char data type.
class CharDemo {
    public static void main(String args[]) {
        char ch1, ch2; 

        ch1 = 88; // code for X
        ch2 = 'Y'; 

        System.out.print("ch1 and ch2: ");
        System.out.println(ch1 + " " + ch2);
    }
}

This program displays the following output:

ch1 and ch2: X Y

glglgl
  • 89,107
  • 13
  • 149
  • 217
  • 3
    https://en.wikipedia.org/wiki/Character_encoding: [0x58 Latin Capital Letter X](https://www.compart.com/en/unicode/U+0058) – Salem Sep 19 '18 at 10:00
  • https://stackoverflow.com/questions/11671908/can-the-char-type-be-categorized-as-an-integer – Tim Sep 19 '18 at 10:01

1 Answers1

2

chars are just smaller integers with fancy formatting. 88 happens to be the unicode value of X, so when you store it in a char, it would be printed that way.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    It happens to also be the ASCII code of X, but in general the "small integer" in a Java `char` is a Unicode code point (the first 127 of those are shared with ASCII). – Thilo Sep 19 '18 at 10:42