`
daisy8564
  • 浏览: 75410 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

一些基础算法

阅读更多
1.字符串的顺序反向输出和数值的引用传递

public class MyClass{

           public static void main(String argv[]){

                      String s="abcdefg";

                      Integer i =new Integer(10);                  

                      MyClass myclass = new MyClass();                    

                      System.out.println(myclass.aaa(i));

                      System.out.println(myclass.reverse(s));

           }



           public Integer aaa(Integer i){

                      int x =i.intValue();

                      x=x*2;                                   

                      return  Integer.valueOf(x);                   

           }

           public static String reverse(String s){

                      int length=s.length();

                      StringBuffer result=new StringBuffer(length);

                      for(int i=length-1;i>=0;i--)

                      result.append(s.charAt(i));

                      return result.toString();

           }

}

2.数值排序

public class Test{   

              public static void main(String[] args)

              {

                  int[] maker ={3,5,7,2,8,1};

                  int[] arry;

                            Test test=new Test();

                            arry=test.f(maker);

                            for(int i=0;i<arry.length;i++){

                                          System.out.println("arry="+arry[i]);

                            }

              }            

              public int[] f(int[] maker)

              {

                            int[] arry=maker;

                            int length=arry.length;

                            for(int i=0;i<length;i++){

                                          for(int j=i+1;j<length;j++){

                                                        if(arry[i]>arry[j]){

                                                                      int temp=arry[j];

                                                                      arry[j]=arry[i];

                                                                      arry[i]=temp;

                                                        }

                                          }

                            }                          

                            return arry;

              }

}

3.字符排序

public class Test{   

              public static void main(String[] args)

              {

                  char[] maker ={'a','g','A','J','e'};

                  char[] arry;

                            Test test=new Test();

                            arry=test.f(maker);

                            for(int i=0;i<arry.length;i++){

                                          System.out.println("arry="+arry[i]);

                            }

              }            

              public char[] f(char[] maker)

              {

                            char[] arry=maker;

                            int length=arry.length;

                            for(int i=0;i<length;i++){

                                          for(int j=i+1;j<length;j++){

                                                        if(arry[i]>arry[j]){

                                                                      char temp=arry[j];

                                                                      arry[j]=arry[i];

                                                                      arry[i]=temp;

                                                        }

                                          }

                            }                          

                            return arry;

              }

}

4.字符串排序

public class Test{   

              public static void main(String[] args)

              {

                  String maker ="agAJe";

                            Test test=new Test();

                            char[] arry1=test.f(maker.toCharArray());

                            String str= new String(arry1);

                            System.out.println("str="+str);

              }            

              public char[] f(char[] maker)

              {

                            char[] arry=maker;

                            int length=arry.length;

                            for(int i=0;i<length;i++){

                                          for(int j=i+1;j<length;j++){

                                                        if(arry[i]>arry[j]){

                                                                      char temp=arry[j];

                                                                      arry[j]=arry[i];

                                                                      arry[i]=temp;

                                                        }

                                          }

                            }                          

                            return arry;

              }

}



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/senmon2004/archive/2006/03/28/641714.aspx
分享到:
评论
2 楼 daisy8564 2012-05-28  
diyunpeng 写道
呵呵,09年刚工作,结果看见了你的博客,转眼3年

呵呵,有缘。现在工作怎么样?
1 楼 diyunpeng 2012-04-26  
呵呵,09年刚工作,结果看见了你的博客,转眼3年

相关推荐

Global site tag (gtag.js) - Google Analytics