请问一下就是在java编程时有时候使用加号有什么作用啊?

xuexidechuangkous 2011-06-15 07:42:30
请问一下就是在java编程时有时候使用加号有什么作用啊?还有就是有时候怎么加号会和双引号一起使用?
...全文
391 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
火光闪耀 2011-06-16
  • 打赏
  • 举报
回复
除非两端都是数值型(代表四则中的+)。否则都代表字符连接。
火光闪耀 2011-06-16
  • 打赏
  • 举报
回复
如果+号的一端是非数值型,则为连接的意思。
要是两端都是数值型,就是四则中的+。
lord_is_layuping 2011-06-16
  • 打赏
  • 举报
回复
This binary operator will concatenate one string to another. E.g.

String str1 = "abc";
String str2 = "def";
String str3 = str1 + str2

results in str3 holding "abcdef".

For mixed operands, if either a or b in (a + b) is a string, concatenation to a string will occur. Primitives will be converted to strings and the toString() methods of objects will be called.

(This is the only case of operator overloading in Java.)

Note that the equivalence operator "+=" will also perform string concatenation.
dandan0912 2011-06-16
  • 打赏
  • 举报
回复
加号和双引号一起使用,加号起连接字符串的作用,如:
String s1 = "AAA"+"BBB";
System.out.println(s1);
加号连接了AAA和BBB字符串,输出结果为AAABBB
IT人.阿标 2011-06-15
  • 打赏
  • 举报
回复
在一般数字运算的时候“+”就是简单的求和运算,当是字符串相加的时候就是字符串连接的作用了。
安心逍遥 2011-06-15
  • 打赏
  • 举报
回复
用于拼接字符串的,比较简单,使用

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧