Computer Applications
What will be the output of the following code?
char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);
Java
Values & Data Types Java
ICSE 2010
82 Likes
Answer
m = 97
Working
The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a' that is assigned to m. But m is an int variable not a char variable. So, through implicit conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.
Answered By
27 Likes
Related Questions
int x = 98; char ch = (char)x; what is the value in ch?
- b
- A
- B
- 97
Consider the following program segment in which the statements are jumbled, choose the correct order of statements to swap two variables using the third variable.
void swap(int a, int b) { a = b; → (1) b = t; → (2) int t = 0; → (3) t = a; → (4) }- (1) (2) (3) (4)
- (3) (4) (1) (2)
- (1) (3) (4) (2)
- (2) (1) (4) (3)
The size of '\n' is:
- 2 bytes
- 4 bytes
- 8 bytes
- 16 bytes