
/** *//**
* 交換兩個數據,可用數組或class
* @author HJH
* @version 1.0,02/19/2008
*/

public class Swap


{
private String s1 = null;
private String s2 = null;
private StringBuffer s3 = null;
private StringBuffer s4 = null;
public Swap(String s1,String s2,StringBuffer s3,StringBuffer s4)

{
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
this.s4 = s4;
}
public void swapString(String str1,String str2)

{
s1 = str2;
s2 = str1;
}
public void swapStringBuffer(StringBuffer str3,StringBuffer str4)

{
s3 = str4;
s4 = str3;
}
public static void main (String[] args)

{
String str1 = "123";
String str2 = "456";
StringBuffer str3 = new StringBuffer("159");
StringBuffer str4 = new StringBuffer("357");
Swap swap = new Swap(str1,str2,str3,str4);
System.out.println("交換前
");
System.out.println(swap.s1 + " "+ swap.s2 + " " + swap.s3 + " " + swap.s4);
swap.swapString(swap.s1,swap.s2);
swap.swapStringBuffer(swap.s3,swap.s4);
System.out.println("交換后
");
System.out.println(swap.s1 + " "+ swap.s2 + " " + swap.s3 + " "+ swap.s4);
}
}
posted on 2008-02-19 23:43
101℃太陽 閱讀(248)
評論(0) 編輯 收藏 所屬分類:
代碼民工