您的位置:首页 > 其它

字符串与数字相加的问题

2017-06-27 14:03 148 查看
题目:

public class Demo {
public static void main(String args[]) {
int x = 10 ;
double y = 20.2 ;
long z = 10L;
String str = "" + x + y * z ;
System.out.println(str) ;
}
}


直奔主题,先看符号优先级,* 优先于+ 所以先* ,此时y,z应当按照数字计算,得到的结果202.0(因为y是浮点型,所以结果也为浮点型)

此时+ 按照从前往后算:str=“”+“10”+“202.0”;

输出:10202.0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string