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