还有个题目
public clsss Test{
public static void main(String[]args)
{
    System.out.println("hello"+args[0]);
}
}执行命令  java Test java hello cao
为什么不能运行呢,还有结果为什么不是hellojava

解决方案 »

  1.   

    public clsss Test{
    clsss改为classpublic static void main(String[]args)
    {
        System.out.println("hello"+args[0]);
    }
    }args[0]  为第一个字符串
    结果为hellohello
      

  2.   

    /*
     * Created on 2004-12-13
     *
     */public class Test {
        public static String stringReplace(String text) {
            text = text.replace('a', 'l');
            return text;
        }    public static String bufferReplace(StringBuffer text) {
            text = text.append("c");
            return text.toString();
        }    public static void main(String args[]) {
            String textString = new String("java");
            StringBuffer sb = new StringBuffer("java");
            textString = stringReplace(textString);
            String s = bufferReplace(sb);
            System.out.println("================");
            System.out.println(textString);
            
            System.out.println(s);
        }
    }
      

  3.   

    1>首先Java中的参数传递机制一直以来大家都争论不休,究竟是“传值”还是“传址(传引用)”,争论的双方各执一词,互不相让。
    因为java中的String是个特殊的类,他是不允许改变的,当你String textString=new String("java"); 
    就建立了一个字符串对象,调用stringReplace(textString); 方法时就把textString字符串所在的空间地址赋给了
    public static void stringReplace(String text){ 
        text=text.replace('j','l'); 
       } 
    中的text引用,当他调用replace方法时,其实是返回一个新的字符串类return new String();也就意味着现在text存储的地址改变了,指向了改变后的字符串.
    而StringBuffer类只是在原有类的基础上修改,所以修改后的字符串仍存储在原来的地址空间上.
    所以你调用stringReplace()时,原来的字符串没有被修改所以仍是原来的植,而bufferReplace()则在原来的基础上进行修改所以输出修改过的.