WARNING!
Java uses the +
operator for both addition and concatenation.
Numbers are added. Strings are concatenated.
If you add two numbers, the result will be a number:
int x = 10;
int y = 20;
int z = x + y; // z will be 30 (an integer/number)
If you add two strings, the result will be a string concatenation:
String x = "10";
String y = "20";
String z = x + y; // z will be 1020 (a String)
If you add a number and a string, the result will be a string concatenation:
String x = "10";
int y = 20;
String z = x + y; // z will be 1020 (a String)
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!