Complete the code to assign the smaller of two numbers to the variable min using the ternary operator.
int a = 10; int b = 20; int min = (a < b) ? [1] : b;
b instead of a for the true case.The ternary operator checks if a < b. If true, it assigns a to min, otherwise b.
Complete the code to assign "Even" or "Odd" to the variable result based on whether num is even or odd.
int num = 7; String result = (num % 2 == 0) ? [1] : "Odd";
num instead of string literals.The ternary operator checks if num % 2 == 0. If true, result is assigned "Even", else "Odd".
Fix the error in the ternary expression to correctly assign the absolute value of number to absValue.
int number = -5; int absValue = (number >= 0) ? number : [1];
number instead of its negation for negative values.number * -1 which is correct but less common than -number.The ternary operator assigns number if it is non-negative; otherwise, it assigns -number to get the absolute value.
Fill both blanks to create a ternary expression that assigns "Pass" if score is 50 or more, otherwise "Fail".
int score = 65; String grade = (score [1] 50) ? [2] : "Fail";
< instead of >= in the condition."Pass" and "Fail".The condition checks if score >= 50. If true, grade is "Pass", else "Fail".
Fill all three blanks to create a ternary expression that assigns the maximum of x and y to max.
int x = 15; int y = 25; int max = ([1] [2] [3]) ? x : y;
< instead of > in the condition.x and y in the condition or result.The ternary operator checks if x > y. If true, max is x, otherwise y.