close
http://www.mblog.com/sanjayvyas/038185.html

一篇關於在四種Language寫Swap function很好的討論文章...:)

Java:
public class SwapApp
{
class Dual
{
public int i;
public int j;
Dual(int i_, int j_)
{
i = i_;
j = j_;
}
}

public static void swap(Dual dual)
{
int c=dual.i;
dual.i=dual.j;
dual.j=c;
}

public static void main(String [] args)
{
int x=5;
int y=7;
Dual obj = new Dual(x, y);
System.out.println("Before swap: x="+x+", y="+y);
swap(obj);
x=obj.i;
y=obj.j;
System.out.println("After swap: x="+x+", y="+y);
}
}


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 iceis 的頭像
    iceis

    .: iceis' Blog :.

    iceis 發表在 痞客邦 留言(2) 人氣()