byte x = 0;
byte y = (--x<0) ? ++x : -x;
System.out.println(y);
Result of the code execution will be:
Explanation
Expression result will have type int, because the type of the third operand of the ternary operator in the result will be int. Therefore, you need explicit conversion for successful compilation.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback