Ask Question
21 July, 04:28

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. 21 July, 05:20
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers