Beginner learner of Java here. Am I right to say that int i is passed into int n1, int j is passed into int n2? But my output is After swapping,i is 1, j is 2 why can't my variables swap? Edit 1: After viewing other posts, some say that there is no such thing as a swapping method for primitive data? Then why did my instructor create this swap method, for confusion?
int i = 1;
int j = 2;
swap(i,j);
System.out.println("After swapping,i is " +i + ", j is " + j);
}
public static void swap(int n1, int n2) {
int temp = n1; //temp =1
n1 = n2; //n1 = 2
n2= temp; //n2 = 1