本帖最后由 枫儿 于 2013-10-13 14:00 编辑
大家帮忙看看,为啥我这段代码打印之后还是原字符串,没有反转- class StringDemo2
- {
- public static void main(String[] args)
- {
- String s=" ab cd ";
- sop("("+s+")");
- fz(s);
- sop("("+s+")");
- }
-
- public static void sop(String sop)
- {
- System.out.println(sop);
- }
- public static String fz (String f)
- {
- char[] chs= f.toCharArray();
- fazh(chs);
- return new String(chs);
- }
- public static void fazh(char[] c)
- {
-
- for (int sta=0,end=c.length-1; sta<=end; sta++,end--)
- {
- saw(c,sta,end);
- }
- }
- public static void saw(char[] d ,int x,int y)
- {
- char temp;
- temp=d[x];
- d[x]=d[y];
- d[x]=temp;
- }
-
- }
复制代码 |