字符串连接符“+”的应用区别

public class Demo11 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a = a+b;
System.out.println(a);
System.out.println("================");
//字符串连接符“+”的应用区别

//""在前,则后面的a、b均转化为String类型;
System.out.println(" "+a+b);
//若a+b在前,则计算a+b。
System.out.println(a+b+"");
//""在中间,则a、b均转化为String类型;
System.out.println(a+" "+b);

System.out.println(a+""+b);
}
}

输出:

30
================
3020
50
30 20
3020

Process finished with exit code 0

posted @ 2021-08-20 09:08  小风扇呜呜呜  阅读(99)  评论(0)    收藏  举报