/** *//**
* 交换两个数据,可用数组或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℃太阳 阅读(240)
评论(0) 编辑 收藏 所属分类:
代码民工