In java, How did last ch++ answer “:;”happen?

char ch='A';
System.out.println(ch); //prints A
ch++;
System.out.println(ch); //prints B
ch='0';
System.out.println(ch); //prints 0
ch++;
System.out.println(ch); //prints 1
ch='9';
System.out.println(ch); //prints 9
ch++;
System.out.println(ch); //prints :

Why did the ch++ make the program print a colon after the 9?

Answer

In ASCII character set : comes after 9, so when you increment you basically go to :.

Take a look at this: enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *