浏览以下内容前,请点击并阅读 声明

对于6种基本的数字类型,java提供了相对应的类。Number类和六种细分的子类。

aaarticlea/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAUcAAACVCAIAAABEqq+sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAKd9JREFUeNrsXQd8FMUe3tkruSR3l0oSQhokhBZK6J3QqwhYAKV3KY8OCk8RpCMICFIFpDxABKQoIE2ahhJBikhHkJ52add33lyubb27BDCbOB/84HZvd2/32/83/zIzuwBCSGBgYJQgkJgCDAysagwMDFFDiikoKExmePL6c5S3kABY1wDHd4B/FyD8hcv9+DYHbr4v/Nf2bbL1psYVgpUKbBtY1f8OaLXaMRM+6jV6uo8cmk2UVdcA2HTLXQQ2TdtW2TbI/0PadUbaVU/aVQvoi/YmwbFI2vXn2BHQFm1NDQDczey/CEjaXoDx64RcKrn2IJOicLUFR+D/HkBoNBohIXqjh668MeS9ACxkrGoMpiLgS4rtNQHknxu0fXD+PmMR2hbtp4j1jVWN8c96XavsAO2D+4YDskVOX3R8D+nfYWBVY7wS/SJZgZfa3V2jILQI6R8xsKoxPHG0wi6U3+UW3HXzenJ6vM341v7T+Xq2LaCVuEyGVY3xcmm2sMsFXNftMrS2bQxpYTaki9k5hhDYZcwStnUlwM4aqxrDbcyqVvvt37W9WrT/yiXzA4P90Bo/P/XWDWs6NK2VnvbCy8vL9XHoIpfKZDnZWQPef2fs8EEhgT6CmucLs+nu2tHu0IVtXUnhzBqrGsOt2C2alFh4PrB35+EDB3yVKgvvJJmVnfX8+TOJRCoYV0N2XC2RkJmZGampzyUSiYvwmxt1s9y1Q8N0YcP8nQHWNFY11q1HqS9FoX+fPHq4dvkX2rxc0j72x88/YNO6lR2a1UZOu1So6utVX3Zu2fDhX/c+mTSmSa2K/Xt0KReq6tGl3eL5s+omxNarGnf00AHk+ZUq9amTP9epWTsyyPeTKRO1eXn+Ad6/nDnZplmD0gHe1eJjfti/J0StmDXj46b1arVt3q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cl8pcT9Uq5nl1wVtQ19RDD9JpQiDq5k0RnQoXSa4orFvAKT1QHINjTBviNnmEoO26yA95uKII0T25sYApHo/PcJHTCc3z84Qul0+6LE41cABArlZ7Ny/P2scOCMHH+QPhZeB5mw3cHNX90SA0A7J2+dCioQtCTU7uw2cZRoPeXmgFbnxUoekq2E0Q5CvPiLYKLirrytMZEV3W0TIAeHzTX491Ac9OOjrMvxirGpFeqUL5DXPGOiZgiB86nW7EiBGl/aP/+Z8mSTLIX7lj+XSVSlVc6NJoNEOGDJFLo4vk16FR99P/FlseaVJcYlYIy5cv32HmTN4GvYQ+gRkD498K/JR/DAysagwMDKxqDAwMrGoMDIzC4/8CDACKDlh1rUOOWQAAAABJRU5ErkJggg==" alt="" />

  注意:Number除了这些子类以外,还有四个子类,其中BigDecimal和BigInteger用于高精度的计算,而AtomicInteger和AtomicLong则用于多线程程序,再次不作介绍。

java的数字类提供了一些功能,如各个数字类会定义一些常量 如最大值,最小值等,此外,这些类还包含一些能够将基本数据类型到字符串的相互转化,以及各进位制的转换。

下表类除了一些Number子类所共有的方法:

方法描述
byte byteValue()
short shortValue()
int intValue()
long longValue()
float floatValue()
double doubleValue()

将该数字对象转化为基本数字类型,并返回

int compareTo(Byte anotherByte)
int compareTo(Double anotherDouble)
int compareTo(Float anotherFloat)
int compareTo(Integer anotherInteger)
int compareTo(Long anotherLong)
int compareTo(Short anotherShort)

将该数字对象与参数对比

boolean equals(Object obj)

判断该数字对象是否与参数相等,如果参数的类型与值和该数字对象相等,则返回true,对于Double和Float类型还有额外的要求,详见API文档

每个数字类还含有一些用于和字符串与各个进位制之间的转换的方法,以下以Integer为例列举:

 方法描述
static Integer decode(String s)将一个字符串转化成位一个Integer对象,字符串的形式可以使十进制(默认),八进制(以0开头)和十六进制(以0x开头)。
static int parseInt(String s)返回一个整数(十进制)。
static int parseInt(String s, int radix)返回一个字符串转化的整数 (radix 代表进位制, 10, 2, 8, 或者 16分别代表十进制,二进制,8进制和16进制 ) 。
String toString()返回一个代表该数字的字符串
static String toString(int i)返回代表一个指定基础类型的整数的字符串
static Integer valueOf(int i)返回一个指定基础类型的整数所对应的Integer类
static Integer valueOf(String s)返回一个由字符串转化的Integer 类,该字符串必须以十进制表示
static Integer valueOf(String s, int radix)返回一个有字符串转化的Integer类,第二个参数指定进位制。

数字输出格式

  利用PrintStream(System.out是一个PrintStream对象)的printf和format方法能够将字符串和数字组合输出。其print方法和println方法只能输出单一对象。

  printf和format方法是相同的,使用语法为:

format(format, Object... )

其中,第一个参数format指定输出的格式,其后可跟若干个输出的对象,使用示例:

int i = 461012;
System.out.format("The value of i is: %d%n", i);

输出格式字符串由文本和格式标识符构成,格式标识符以%开始,以转换字符结束,转换字符是一个表明数据类型的字符,格式标识符中间可以有其他的标记和标识符,详见java.util.Formatter

此外,java.text.DecimalFormat类也可用于控制数字中的开始和结尾的零,前后缀,分组和小数点。

对于数字,java提供了Math类进行一些高级的书序运算如求绝对值,三角函数,指数函数等。

此外Math类还提供了ramdom方法用来产生一个随机数字:

// 0.0 <= Math.random() < 1.0,因此如下句子将产生一个0-10的随机整数
int number = (int)(Math.random() * 10);

如果需要产生一系列的随机数,还可用java.util.Random

Autoboxing

Autoboxing是java教程中的一个术语,简单说就是自动转化,在写java代码时,我们可以直接将基础数据类型赋值给其对应的java对象的变量,其中有一个自动转化的过程,这是由编译器自动完成的。如int赋值给Integer变量。反过来叫unboxing,其实也是一种自动转化,只是转换方向相反,姑且叫自动逆转化吧。

自动转化和自动逆转化在以下情况会发生:

  赋值及其它运算

  方法的参数传递

如:

public static int sumEven(Integer li) {
int sum = 0;
//取余操作符%和+=不能对Integer对象使用,此处编译器会将Integer对象转化成int类型(unboxing)
if (i % 2 == 0)
sum += i;
return sum;
}
04-27 05:02