Java中使用下划线分隔超大数字(干货)

更新时间:2023-07-13 00:42:51 阅读: 评论:0

房屋租赁合同简易版Java中使⽤下划线分隔超⼤数字(⼲货)
笛子的英语Java 中下划线分隔数字
订阅原⽂学习更多 Java 知识
Java 7 以后,数字⽂字中数字之间的任意位置都可以出现任何数量的下划线字符(_),通过下划线(_)你可以把数字按组进⾏分开。从⽽可以可以提⾼代码的可读性。
下⾯的例⼦介绍如何使⽤ _ 作为数字之间的分隔符考评表
long creditCardNumber =1234_5678_9012_3456L;
帆船模型
long socialSecurityNumber =999_99_9999L;
float pi =3.14_15F;
long hexBytes =0xFF_EC_DE_5E;紫苏焖鸭
long hexWords =0xCAFE_BABE;
long maxLong =0x7fff_ffff_ffff_ffffL;
byte nybbles =0b0010_0101;cad文件
雌雄大老千long bytes =0b11010010_01101001_10010100_10010010;
注意: 你只能在数字之间添加下划线,不能在下⾯位置添加下划线。
在数字的开头或者结尾
与浮点⽂字中的⼩数点相邻
后缀 F 或 L 之前
在需要⼀串数字的位置
float pi1 =3_.1415F;// Invalid; cannot put underscores adjacent to a decimal point
float pi2 =3._1415F;// Invalid; cannot put underscores adjacent to a decimal point
long socialSecurityNumber1
=999_99_9999_L;// Invalid; cannot put underscores prior to an L suffix
int x1 = _52;// This is an identifier, not a numeric literal
踉踉跄跄int x2 =5_2;// OK (decimal literal)
int x3 =52_;// Invalid; cannot put underscores at the end of a literal
int x4 =5_______2;// OK (decimal literal)
int x5 =0_x52;// Invalid; cannot put underscores in the 0x radix prefix
int x6 =0x_52;// Invalid; cannot put underscores at the beginning of a number
int x7 =0x5_2;// OK (hexadecimal literal)
int x8 =0x52_;// Invalid; cannot put underscores at the end of a number
int x9 =0_52;// OK (octal literal)
int x10 =05_2;// OK (octal literal)
int x11 =052_;// Invalid; cannot put underscores at the end of a number
reference

本文发布于:2023-07-13 00:42:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1093416.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数字   位置   添加   出现   只能   简易版   订阅
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图