• 数据运算中关于字符串""的拼接问题


      例子中准备了3种类型数据,分别针对是否在运算存在空字符串参与运算进行了演示,结果如下:

     1         int x = 10;
     2         double y = 20.2;
     3         long z = 10L;
     4         System.out.println(x + y); // 30.2
     5         System.out.println(x + y * z); // 212.0
     6         System.out.println("" + x + y * z); // 10202.0
     7         System.out.println("" + y * z + x); // 202.010
     8         System.out.println(x + y * z + ""); //212.0
     9         System.out.println("" + x + y); // 1020.2
    10         System.out.println("" + (x + y * z)); // 212.0    

    结论:(在未添加括号情况下)

      空字符串""参与数据运算时:若""在数据运算的表达式中出现(除末尾),其后面的数据运算直接进行简单拼接实现(如:6、7、8、9行)。

  • 相关阅读:
    C#生成唯一码方法
    解剖常用软件程序都用什么语言开发
    Unity3D笔记七 GUILayout
    函数的递归
    函数
    函数的参数
    函数的返回值
    函数的定义
    文件处理
    集合
  • 原文地址:https://www.cnblogs.com/moreforests/p/13221582.html
Copyright © 2020-2023  润新知