What is the output of System.out.println('z' - 'a')? Group of answer choices2526az
Question
What is the output of System.out.println('z' - 'a')
?
Group of answer choices
25
26
a
z
Solution
The output of System.out.println('z' - 'a') in Java is 25.
Here's why:
In Java, char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive). When you subtract 'a' from 'z', you're actually subtracting their ASCII values.
The ASCII value of 'a' is 97 and 'z' is 122. So, when you subtract 'a' from 'z' (i.e., 122 - 97), you get 25.
So, System.out.println('z' - 'a') prints 25.
Similar Questions
What will the following print out?String shout = "hello";shout = shout.toUpperCase();System.out.println(shout);Group of answer choicesHELLO
What is the output of the following code snippet?int x = 5;int y = 2;int result = x % y;System.out.println(result);Question 2Answera.3b.2c.1d.0
What is the output of the following code snippet?int x = 8;int y = 4;System.out.println(x & y);Question 16Answera.8b.0c.1d.4
Choose the correct answerWhat is the output of the following code snippet?a = 0xBeeb = 0o123456print(a|b) Options45308427994569844224
Choose the correct answer What is the output for the below program? def x(y,z): pass x(1,4) Options 1,4 y,z No output None
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.