加号 + 的使用
1. 字符串的拼接
示例代码
public class hello{
public static void main(String[] args){
System.out.println("jackson"+"在"+"学Java");
}
}
`jackson在学Java`
注意:在字符串变量先前定义后,可以使用+=进行拼接
代码示例
public class test{
public static void main(String[] args){
String name = "jackson";
name += "在学Java";
System.out.println("jackson在学Java");
}
}
2. 输出加法的结果
public class hello{
public static void main(String[] args){
System.out.println(10+10);
}
}
输出:20
3. 混合使用(区别以下二者)
案例一
public class hello{
public static void main(String[] args){
System.out.println(100+3+"hello");
}
}
输出:103hello
案例二
public class hello{
public static void main(String[] args){
System.out.println("hello"+100+3);
}
}
输出:hello1003
注意:计算机的运行是从左到右,从上到下逐步运行的