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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 石泉县| 嫩江县| 洪雅县| 雅安市| 南召县| 南和县| 邹平县| 远安县| 麻城市| 延津县| 聊城市| 镇平县| 台州市| 修武县| 南京市| 阳曲县| 凉城县| 平泉县| 和田市| 江孜县| 江北区| 内黄县| 克拉玛依市| 河北区| 得荣县| 泗阳县| 甘德县| 哈尔滨市| 德格县| 抚松县| 蓝山县| 镇远县| 达日县| 育儿| 姜堰市| 蒙城县| 上饶县| 宿州市| 靖西县| 浏阳市| 梁山县|