黑马程序员技术交流社区

标题: 求大神们看看这个程序有什么问题 [打印本页]

作者: kmlitheima    时间: 2015-6-4 09:20
标题: 求大神们看看这个程序有什么问题
程序总是报错::::什么原因造成的

class Example1
{
        String str=new String("good");
        char[]ch={'a','b','c'};
        public  void change(String str,char[] ch){
           str="test ok!";
            ch[0]='g';
       System.out.print(str);
        System.out.println(ch);
          }
   }
class Example
{
public static void main(String args[]){
           Example1 ex=new Example1();
           ex.change(ex.str,ex.ch);
           System.out.print(ex.str+" and ");
      System.out.println(ex.ch);
          }
}


作者: kmlitheima    时间: 2015-6-4 10:18
zhangkai986745 发表于 2015-6-4 10:07
报的是什么错误?

  public  void change(String str,char[] ch){
           str="test ok!";
            ch[0]='g';
       System.out.print(str);
        System.out.println(ch);
          }

System.out.print(ex.str+" and ");
      System.out.println(ex.ch);
都是在最后报错,不知道为啥错了?

作者: 探索者    时间: 2015-6-4 10:33
刚才帮你试了一下,你的程序本身并没有问题,只是出现了一个不常见的错误,即在出错地方的大括号前面多了一些全角空格,字符表现形式为‘\u3000’,一般在编程不会出现的,你只要删除那些大括号”}“前的全角空格就可以了。
作者: mmakun    时间: 2015-6-4 10:46
没发现有什么错误




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2