我想用数组实现字符串的翻转.写了这样一段代码.提示有一个错误.哪位高手帮忙看一下,给改一下.谢谢.急用!
public class sy
{
 public static void main(String[] args)
 {
  int i=0;
  String string="abcd"
  String[] a=string.getBytes();
  String[] b=new bytes[string.length()];
  for(i=0;i<string.length();i++)
   {
   b[string.length-i-1]=a[i];
   }
 {
 System.out.println(a[i]);
 }
System.out.println(b[i]);
  }
}提示错误:sy.java:7: ';' expected
  String[] a=string.getBytes();
  ^
1 error

解决方案 »

  1.   

    String[] a=string.getBytes();
      String[] b=new bytes[string.length()];--------------怎么楼主一点基础都没的吗?
    都getBytes了,你还String[],都new byte[](不是bytes),还String[]byte[]
      

  2.   

    建议还是用char[] c = str.toCharArray();
    不然碰到中文之类的就出问题了
      

  3.   

    StringBuffer sb = new StringBuffer("abcdefg");
    System.out.println(sb.reverse().toString());
      

  4.   

    语法错误: String string="abcd"后边丢了分号