String改成StringBuffer比较好点.不然要浪费空间.

解决方案 »

  1.   

    void 函数里还return str?
      

  2.   

    void 怎么还返回啊应该是
    public static String getCountTest(int count){
        //code
    }
      

  3.   

    所有以get为开头的函数都不应该返回void,set才返回void
      

  4.   

    这样应该ok了!
    public static String getCountTest(int count){
          StringBuffer str=new StringBufer("");
          for(int i=0;i<count;i++){
              char ch="A";
              str.append(ch);
          }
          return str;
    }
      

  5.   

    优化?
    请楼主先运行正确在予以考虑吧public static String getCountTest( int count ) {
      // String str=new String(""); 不建议
      String str = "";   
     
      // 楼主的循环似乎只是不断添加字符A于字符串尾端,
      // 这里不需要特地申明一个char变量了吧
      for( int i = 0; i < count; i++ )
        // char ch="A";  Wrong,char类型不能用双引号赋值?
        // str+=ch;
        str += "A";  return str;
    }