Swap Two Values
Easyjava
Read two integers a and b, swap their values using a third temporary variable, and print them after the swap.
Input: two integers separated by whitespace.
Output: one line: a=<a> b=<b> using the values after the swap.
Example 1
Input
10 20
Output
a=20 b=10
- -1000000 <= a, b <= 1000000
Hint 1
int temp = a; a = b; b = temp;
Hint 2
Print with concatenation: "a=" + a + " b=" + b.
Copy a into temp, move b into a, then move temp into b. Printing afterwards shows the values have exchanged.