问答详情
源自:2-4 变量是什么

这是什么问题呢?谢谢大神们

1,  public class HelloWorld{    public static void main(String[] args) { String hobby="慕课网"; System.out.println(+hobby); } } 2,  public class HelloWorld{    public static void main(String[] args) { String hobby="慕课网"; System.out.println(""+hobby); } } 第一个不能执行第二个可以不加“”为什么就不对?

提问者:精慕门3369224 2017-05-23 12:46

个回答

  • 九尾小狐妖狐魅
    2017-05-26 19:44:48

    public class HelloWorld{

        public static void main(String[] args) {

    String hobby="慕课网";

    System.out.println(hobby);

    }

    }

    这就可以了 加之类的输出根本不需要  下面已经有输出了 输出的变量为 hobby

  • 想不睡
    2017-05-23 13:17:00

    +在这里表示拼接字符串,将变量hobby的值拼接到+前面的字符串后面,+前面没有字符串的话就会报错了

  • 慕姐4345033
    2017-05-23 13:10:48

    The operator + is undefined for the argument type(s) String