字符串与数字相加的问题
2017-06-27 14:03
148 查看
题目:
直奔主题,先看符号优先级,* 优先于+ 所以先* ,此时y,z应当按照数字计算,得到的结果202.0(因为y是浮点型,所以结果也为浮点型)
此时+ 按照从前往后算:str=“”+“10”+“202.0”;
输出:10202.0
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
相关文章推荐
- as3计算字符串和数字相加时的悲催问题
- as3计算字符串和数字相加时的悲催问题
- 导出 excel 数字字符串 问题
- javascript的字符串转换为数字的问题
- 按字符串中的数字排序问题
- MySQL字符串中数字排序的问题
- Objective-C 的基本数据类型、数字、字符串和集合等介绍 (retaincount 释放问题)
- 两个数字字符串相加生成新的字符串
- (php的弱类型导致的小问题)某变量可能是数字或非数字(对象、字符串、json等)时,应该如何去判断
- 大数问题:用字符串解决大数相加和相乘。【转】
- 关于Devexpress xtraGrid中数字字段删除数字后出现输入字符串格式不正确问题的解决方案
- 大数问题:用字符串解决大数相加和相乘
- php下关于中英数字混排的字符串分割问题
- vc中数字和字符串的转换问题
- ie6下报错缺少标识符、字符串或数字 问题解决
- 关于sql中字符串中取数字问题
- javascript 数字相加的时候要进行一下处理,不然就是字符串相加
- 关于中英数字混排的字符串分割问题
- 大数问题:用字符串解决大数相加和相乘