java中2个数据的交换如何实现??
class pt
{
int x,y;
pt(int x,int y)
{
this.x=x;
this.y=y;
}
}
////////////////////////////////////////////////////////
class test
{
static void swap(int m,int n)
{
int temp;
temp=m;
m=n;
n=temp;
}
static void change(pt a,pt b)
{
pt temp;
temp=a;
a=b;
b=temp;
}
public static void main(String[] args)
{
int m1=1;
int n1=2;
swap(m1,n1);
System.out.println(m1);
System.out.println(n1);
pt p1=new pt(1,2);
pt p2=new pt(3,4);
change(p1,p2);
System.out.println(p1.x);
System.out.println(p1.y);
System.out.println(p2.x);
System.out.println(p2.y);
}
}
//输出1 2 1 2 3 4,问想输出2 1 3 4 1 2要怎么写??忘高手指点~~~