日期:2014-05-20  浏览次数:20574 次

请问此程序哪里有错误?望改之~谢谢
public   class   Wt   {
        void   test(String[]   src)  
        {
String   str= " ";
for   (int   i=0;i <src.length;i++)
{
str+=src[i];
if(i <src.length-1)
      str+= ", ";
}
System.out.println(str);
}
        public   static   void   main(String[]   args)   {
        Wt   c=new   Wt();
        int   a[5];
        for   (int   j=0;j <5;j++)
              a[j]=System.in.read();
        c.test(a);
}
}

编译错误:需要 '] ';

请问怎么解决?

------解决方案--------------------
1. int a[5];需要初始化:int[] a = new int[5];
2. c.test(a);方法参数类型不匹配。wt类里面定义的test方法参数是String[]类型
3. for (int i=0;i <src.length;i++) 最好要判断下src是否为null,否则可能出现异常