首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请教此程序哪里有错误?望改之~多谢

2011-11-20 
请问此程序哪里有错误?望改之~谢谢publicclassWt{voidtest(String[]src){Stringstr for(inti0i sr

请问此程序哪里有错误?望改之~谢谢
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,否则可能出现异常

热点排行