Maximum

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
int a = 7, b = 21;
a > b ? a : b 

Answer:

The expression is evaluated to 21.

Maximum

The expression evaluates to the maximum of two values:

  1. The condition a > b is false, so
  2. The part after the colon (:) is evaluated, to 21.
  3. The entire expression evaluates to that value.

(Usually such an expression is part of a longer statement that does something with the value.) Here is a program fragment that prints the minimum of two variables.

int a = 7, b = 21;
System.out.println( "The min is: " + (a ______ b ? a : b ) );

Other than the blank, the fragment is correct. The value of the conditional expression can be used with the concatenation operator + in the println() statement.

QUESTION 3:

Fill in the blank so that the program fragment works correctly.