Java基础_赋值运算

 * short s=1;s = s+1;

运算错误,提示损失精度。因为s+1为int类型,int类型赋值给short类型会损失精度

ps:精度变化由小到大为  byte->short->int->long ,反过来就会损失精度


 * short s=1;s+=1;

结果为2.

+=是一个赋值运算符。可以理解为 (short) s = (short) (s+x)

posted @ 2016-09-24 22:46  Lyxin_c  阅读(157)  评论(0编辑  收藏  举报