Java中数字中使用下划线--起什么作用呢?
下文笔者讲述数字中间下划线的功能及简介说明,如下所示
数字中下划线 是JDK7中引入的新功能 其主要功能是方便阅读例:数字下划线的示例
package com.java265.example.basic; public class UnderscoreNumericExample { public static void main(String[] args) { // 使用下划线写数字文字是一种更简单的方法 // 阅读长号。 int maxInt = 2_147_483_647; int minInt = -2_147_483_648; if (maxInt == Integer.MAX_VALUE) { System.out.println("maxInt = " + maxInt); } if (minInt == Integer.MIN_VALUE) { System.out.println("minInt = " + minInt); } // 使用数字以二进制或十六进制文字形式写数字 // 下划线。 int maxIntBinary = 0B111_1111_1111_1111_1111_1111_1111_1111; int maxIntHex = 0X7____F____F____F____F____F____F____F; System.out.println("maxIntBinary = " + maxIntBinary); System.out.println("maxIntHex = " + maxIntHex); } } -----运行以上代码,将输出以下信息----- maxInt = 2147483647 minInt = -2147483648 maxIntBinary = 2147483647 maxIntHex = 2147483647
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。