Computer Applications
Evaluate the value of n if value of p = 5, q = 19
int n = (q – p) > (p – q) ? (q – p) : (p – q);
Java Operators
ICSE 2015
127 Likes
Answer
int n = (q – p) > (p – q) ? (q – p) : (p – q)
⇒ int n = (19 - 5) > (5 - 19) ? (19 - 5) : (5 - 19)
⇒ int n = 14 > -14 ? 14 : -14
⇒ int n = 14 [∵ 14 > -14 is true so ? : returns 14]
Final value of n is 14
Answered By
71 Likes
Related Questions
Evaluate the expression when x is 4:
x += x++ * ++x % 2;
A student executes the following code to increase the value of a variable ‘x’ by 2.
He has written the following statement, which is incorrect.
x = +2;What will be the correct statement?
A. x +=2;
B. x =2;
C. x = x +2;- Only A
- Only C
- All the three
- Both A and C