Write an expression using the conditional operator (? :) that compares the value of the variable x to 5 and results in: x if x is greater than or equal to 5 -x if x is less than 5

Write an expression using the conditional operator (? :) that compares the value of the variable x to 5 and results in: x if x is greater than or equal to 5 -x if x is less than 5

LANGUAGE: JAVA

CHALLENGE:

Write an expression using the conditional operator (? 🙂 that compares the value of the variable x to 5 and results in: x if x is greater than or equal to 5 -x if x is less than 5

SOLUTION:

(x >= 5 ? x : -x)

Add comment