Ask Question
8 June, 09:52

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).

+3
Answers (1)
  1. 8 June, 13:16
    0
    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!
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers