Multiple choice

String s1 = "Hello", s2 = "Hi"; //Which code exchanges their values?

  1. String temp = s2; s2 = s1; s2 = temp;

  2. String s1 = temp; s1 = s2; s1 = temp;

  3. String temp = s1; s1 = s2; s2 = temp;

  4. String temp = s1; s1 = s2; s1 = temp;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To swap two variables, you must store one in a temporary variable, assign the second to the first, and then assign the temporary value to the second. Option C correctly performs this sequence.