public class SwapVars { public static void main(String[] args) { int a = 1, b = 2; int help; // Helper variable to hold a value // Code to swap values in a and b help = a; // Now a is "free" a = b; // Perform first half of the swap b = help; // Perform second half of the swap } }