Computer Applications
Predict the output of the following code snippet:
char ch='B',
char chr=Character.toLowerCase(ch);
int n=(int)chr-10;
System.out.println((char)n+"\t"+chr);
Java
Java Library Classes
ICSE Sp 2025
1 Like
Answer
X b
Working
Step-by-Step Execution:
char ch = 'B';
ch
is assigned the character'B'
.
char chr = Character.toLowerCase(ch);
Character.toLowerCase(ch)
converts'B'
to its lowercase equivalent'b'
.chr = 'b'
.
int n = (int) chr - 10;
(int) chr
converts the character'b'
to its ASCII value.- ASCII value of
'b'
is 98. n = 98 - 10 = 88
.
System.out.println((char) n + "\t" + chr);
(char) n
: Converts the integer88
back to a character.- ASCII value
88
corresponds to the character'X'
.
- ASCII value
+ "\t" +
adds a tab space between the characters.chr
: The value ofchr
is'b'
.
Answered By
1 Like
Related Questions
How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }
Write the output of the following String methods:
String x= "Galaxy", y= "Games";
(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));
A student is trying to convert the string present in x to a numerical value, so that he can find the square root of the converted value. However the code has an error. Name the error (syntax / logical / runtime). Correct the code so that it compiles and runs correctly.
String x= "25"; int y=Double.parseDouble(x); double r=Math.sqrt(y); System.out.println(r);
Consider the following program segment and answer the questions below:
class calculate { int a; double b; calculate() { a=0; b=0.0; } calculate(int x, double y) { a=x; b=y; } void sum() { System.out.println(a*b); }}
Name the type of constructors used in the above program segment?