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); } } 第一个不能执行第二个可以不加“”为什么就不对?
public class HelloWorld{
public static void main(String[] args) {
String hobby="慕课网";
System.out.println(hobby);
}
}
这就可以了 加之类的输出根本不需要 下面已经有输出了 输出的变量为 hobby
+在这里表示拼接字符串,将变量hobby的值拼接到+前面的字符串后面,+前面没有字符串的话就会报错了
The operator + is undefined for the argument type(s) String