package javabean;复制代码
- <BLOCKQUOTE>
class Demo2
{
public static void main(String[] args)
{
String s = "abcde";
resverse(s, 0, 4);
}
public static void resverse(String str, int x, int y)
{
char[] ch = str.toCharArray();
for (int start = x, end = y - 1; y > x; x++, y--) {
swap(ch, start, end);
System.out.println(start+"--"+end+"换位置");//加上这句话你输出试试
}
System.out.println(new String(ch));
}
public static void swap(char[] ch, int x, int y)
{
char temp = ch[x];
ch[x] = ch[y];
ch[y] = temp;
}
}
你i的否循环有问题
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |