Ask 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 all three are already declared and that name1 and name2 have been assigned values).

Answers (1)
  1. 1 June, 16:33
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers
Sign In
Ask Question