Given the string variables name1 and name2, write a fragment of code that assigns the larger of the two to the variable first (assume that all three are already declared and that name1 and name2 have been assigned values).

Respuesta :

To screw with your teacher:

first = (name1 > name2 ) ? name1 : name2;

That code is correct, but your teacher is probably looking for:

if( name1 > name2 )
    first = name1;
else
    first = name2;

I love the ternary operator!