- package StringTest;
- public class ReverseTest {
-
- public void function(String str,int i,int j)
- {
- char[] ch;
- ch = str.toCharArray();
- reverse(i,j,ch);
- }
-
- public void function(String str)
- {
- char[] ch;
- ch = str.toCharArray();
- reverse(0,ch.length-1,ch);
- }
-
- public void reverse(int i,int j,char[] ch)
- {
- int k;
- char a;
- k = ch.length-1;
- while(i<=(i+j)/2&&i<=k&&j<=k&&i<=k)
- {
- a = ch[i];
- ch[i] = ch[j];
- ch[j] = a;
- i++;
- j--;
- }
- String str = new String(ch);
- System.out.println(str);
- }
-
- public static void main(String[] str)
- {
- ReverseTest r = new ReverseTest();
- r.function("abcdefg", 3, 6);
- r.function("abcdefg");
- }
- }
复制代码 |
|