int a, c, d; boolean b; ... int a = b ? c : d; // or, with explicit parentheses: int a = ( b ? c : d ); // is shorthand for: if ( b ) { a = c; } else { a = d; } // similarly: int a, b, c, d, e; ... e = a == b ? c : d; // or, with explicit parentheses: e = ( ( a == b ) ? c : d ); // is shorthand for: if ( a == b ) { e = c; } else { e = d; } // The way you most often get in trouble with ? : is this: out.println ( ( big ? "elephant" : "mouse" ) + " is an animal."); // The ( ) are mandatory. Without the ( ) it means: out.println ( big ? "elephant" : ( "mouse" + " is an animal.") );