hjh132's Blog
          If a thing is worth doing it is worth doing well.
          posts - 20,comments - 9,trackbacks - 0
          /**
           * 交換兩個數據,可用數組或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℃太陽 閱讀(256) 評論(0)  編輯  收藏 所屬分類: 代碼民工

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 叶城县| 南郑县| 香港 | 剑阁县| 嵊州市| 利辛县| 金寨县| 洛南县| 商城县| 汽车| 广元市| 额敏县| 阿尔山市| 瑞丽市| 锡林浩特市| 砚山县| 保亭| 鄂尔多斯市| 遂昌县| 汪清县| 卢氏县| 涟水县| 德惠市| 漯河市| 蚌埠市| 凌源市| 抚宁县| 富民县| 儋州市| 会昌县| 稷山县| 沅江市| 临漳县| 荔波县| 奉贤区| 恩平市| 河西区| 广饶县| 定结县| 昭苏县| 桐乡市|