pointer 学习 之 swap

public class swap
{
public void sswap(int x,int y){
int s;
s=x;
x=y;
y=s;
System.out.println("Within sswap: x="+x+" y="+y);
}
public static void main(String args[]){
int x=10,y=7;
System.out.println("x="+x+" y="+y);
swap s=new swap();
s.sswap(x,y);
System.out.println("x="+x+" y="+y);

}
}

输出结果:

x=10,y=7

within sswap:x=7,y=10

x=10,y=7

传进sswap()方法内的仅仅是值而已。

posted @ 2014-02-04 19:32  丸子No1  阅读(237)  评论(0编辑  收藏  举报