Java question about characters and concatation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java question about characters and concatation

When I run this program I get the answer 50. Why is that? Thank you for the feedback! public class Program { public static void main(String[] args) { System.out.println('1' + 1); } }

25th May 2019, 7:53 PM
Markie Alicia
Markie Alicia - avatar
3 Answers
+ 2
on my idea in this code when the compiler come on the '1' use the ASCII number of it and plus to one . hope its usefull !!
25th May 2019, 9:26 PM
AM~GH
AM~GH - avatar
+ 1
'1' is character 1. in table of chars it have number of order, here 49, you can this numbers calculate to sum or compare with < > ==. for print 11 use double quotes "1"+1
25th May 2019, 8:31 PM
zemiak
0
java does not use ASCII but Unicode. Unicode include ASCII. char c = '\u263A'; //unicode number for smile int i = c; System.out.println(c); System.out.println(i); //9786 System.out.println(c == i); //true
26th May 2019, 6:50 AM
zemiak