+ 在Java中有两种使用情况:
第一种情况:+两端都为数值类型,为加法运算第二种情况:+两端只要有一端为String类型,此时+为字符串拼接;则结果类型一定为String
System.out.println(a+“hello”+b);//5hello2 System.out.println(a+b+“hello”);//7hello //System.out.println(a+true+“hello”);//编译报错 System.out.println(a+“hello”+true);//5hellotrue System.out.println(a+b+“hello”+true); // 7hellotrue System.out.println(“hello”+true+a+b); // hellotrue52**
System.out.println(a+“hello”+b);//5hello2 System.out.println(a+b+“hello”);//7hello //System.out.println(a+true+“hello”);//编译报错 System.out.println(a+“hello”+true);//5hellotrue System.out.println(a+b+“hello”+true); // 7hellotrue System.out.println(“hello”+true+a+b); // hellotrue52