Java help needed | Sololearn: Learn to code for FREE!


Java help needed

char b = 'a' + 2; System.out.print(b); I am facing issue while getting correct answer for this. people are giving varying answers and contradicting to the correct one which is provided by sololearn. Please help me with this

10/1/2017 12:03:59 PM

Ravi Shankar

7 Answers

New Answer


should be 'c' ... do you need an explanation why ? or what is the question ^^


You're getting that because it's the ASCII value of the char. char is actually an integer type. It stores the 16-bit Unicode integer value of the character in question. You can look at something like to see the different values for different characters.


alijany already said it, it is because a char (eg. 'a') instead of a string (eg "a") has a fix ASCII value. by adding a numeric value to it you get the next ASCII value in the line ... so bei adding 2 to the value of a you get c. you can google ascii table to see some examples and play around with it


here is somthing to work with.^^ public class Program { public static void main(String[] args) { int a = 'a'; char b = 98; System.out.println(a); // prints value of 'a' System.out.println(b); // prints char of value 98 } }


sorry idont understand. i dont know the answer too. please help me with that also


yes, an explanation would be great.Thanks


Thank you all