+ 3
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
7 Antworten
+ 3
should be 'c' ... do you need an explanation why ? or what is the question ^^
+ 4
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 http://asciitable.com to see the different values for different characters.
+ 3
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
+ 2
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
}
}
0
sorry idont understand.
i dont know the answer too.
please help me with that also
0
yes, an explanation would be great.Thanks
0
Thank you all