num1和num2作为全局变量存储起来就可以了,比如
int num1,num2;
public void swap(int num1,int num2){
int temp = num1;
this.num1=num2;
this.num2=temp;
}
public static void main(String[] args) {
T t = new T();
t.swap(3 , 4);
System.out.println("num1 = " + t.num1);
System.out.println("num2 = " + t.num2);
} |