How do I get this working because the swap is not working as intended? I believe that my scope of my local variables is incorrect and I am having trouble where to place them. My code outputs 4, 5 but it's supposed to output 5, 4. I also can't add a print statement in the swap method.
public class SwapTest {
public static void main(String[] args) {
int num1 = 4;
int num2 = 5;
swap(num1, num2);
System.out.println(num1 + " " + num2);
}
//a method that swaps the values of two int variables.
public static void swap(int num1, int num2){
int num3;
num3 = num1;
num1 = num2;
num2 = num3;
}
}