I’m trying to understand the logic in how to write below statement involving swap/exchange operators. I have googled and searched the text (java intro to problem solving) without any luck thus far. Has anyone struggled on the following before and maybe found an answer (this is an example on strings but I am struggling with swap operators using temp in general):
There are two String variables, s1 and s2, that have already been declared and initialized. Write some code that exchanges their values.
I know I am supposed to use a temp variable and that is exactly where my logic is null.
The way I wrote it and I know its wrong is the following:
temp = s1;
s2 = temp;
In all languages: