本帖最后由 杨道红 于 2013-12-26 19:13 编辑
- public class MyReverce {
- public static void main(String[] args) {
- String s = "kjf da sdabc";
- String s1 = method_reverce(s);
- String s2 = method_reverce(s,3,5);
- sop(s);
- sop(s1);
- sop(s2);
- }
- public static String method_reverce(String str){
- //return method_reverce(str,0,str.length()-1);
- return method_reverce(str,0,str.length)
- }
- public static String method_reverce(String str, int start , int end){
- char[] ch = str.toCharArray();
- for(;start<end;start++,end--){
- //change(ch,start,end)
- change(ch,start,end-1);
- }
- return new String(ch);
- }
- public static void change(char[] arr,int b,int c){
- char temp = arr[b];
- arr[b] = arr[c] ;
- arr[c] = temp;
- }
- public static void sop(Object obj){
- System.out.println(obj);
- }
- }
复制代码 |