本帖最后由 rolan 于 2015-4-29 22:51 编辑
- class String1{
- public static void main(String[] args){
- String s=" abvcxd ";
- sop(s);
- // s=myTrim(s);
- // sop(s);
- // sop(reverseString(s,5,6));
- sop(reverseString(s));//[color=Red]提示我这里出了问题[/color]
- }
- public static void sop(Object obj){
- System.out.println(obj);
- }
- public static String reverseString(String s,int start,int end){
- char[] chs=s.toCharArray();
- reverse(chs,start,end);//[color=Red]提示我这里出了问题[/color]
- return new String(chs);
- }
- public static String reverseString(String s){
- return reverseStringth());//[color=Red]提示我这里出了问题[/color]
- }
- private static void reverse(char[] chs,int start,int end) {
- for(int x=start,y=end;x<y;x++,y--){
- swap(chs,start,end);
- }
-
- }
- private static void swap(char[] chs, int start, int end) {
- char temp=chs[start];
- chs[start]=chs[end];
- chs[end]=temp;
-
- }
- public static String myTrim(String x){
- int start=0;
- int end=x.length()-1;
- while(start<end&&x.charAt(start)==' '){
- start++;
- }
- while(start<end&&x.charAt(end)==' '){
- end--;
- }
- return x.substring(start, end+1);
- }
- }
复制代码 |
|