Question:

The output of the statement: \texttt{System.out.println(Character.toUpperCase('b') + 2); is:}

Show Hint

In Java, characters used in arithmetic expressions are automatically converted into their ASCII/Unicode values. Also remember: \texttt{'A'} = 65, \texttt{'B'} = 66, and \texttt{'b'} = 98.
  • 66
  • 100
  • 68
  • 98
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Understand the function \texttt{Character.toUpperCase('b')}.
The function \texttt{Character.toUpperCase('b')} converts the lowercase character \texttt{'b'} into its uppercase form. So: \[ \texttt{Character.toUpperCase('b')} = \texttt{'B'} \] Thus, the character obtained is \texttt{'B'}.
Step 2: Find the ASCII value of the character.
In Java, when a character is used in an arithmetic expression, it is automatically converted into its ASCII (or Unicode) integer value. The ASCII value of: \[ \texttt{'B'} = 66 \] So now the expression becomes: \[ 66 + 2 \]
Step 3: Perform the addition.
Now add 2 to 66: \[ 66 + 2 = 68 \] So the output printed by the statement will be: \[ 68 \]
Step 4: Compare with the given options.
  • (A) 66: Incorrect. This is only the ASCII value of \texttt{'B'} before adding 2.
  • (B) 100: Incorrect. This does not match the evaluated result.
  • (C) 68: Correct. This is the final value after converting \texttt{'b'} to \texttt{'B'} and adding 2.
  • (D) 98: Incorrect. This is the ASCII value of lowercase \texttt{'b'}, not the final result.
Therefore, the correct output is 68.
Final Answer:68.
Was this answer helpful?
0
0

Questions Asked in ICSE Class X board exam

View More Questions