- 整数Integer,BigInteger
- 浮点数Float,Double,BigDecimal
- 随机数Random
- 数学类Math
java官方文档中文版百度网盘下载链接:
https://pan.baidu.com/s/1xGgGmlEZ3qVEKTkG-Ucqow
提取码:zorj
一.整数类
-
Integer
Integer a=new Integer(9);
Integer b=new Integer(11);
System.out.println(Integer.compare(9, 11));//比较两个整数大小,返回int,输出-1
System.out.println(a.compareTo(b));//数字比较两个 Integer对象。返回int,输出-1
System.out.println(Integer.decode("99"));//字符串转int,将 String解码成 Integer 。
System.out.println(a.hashCode());//返回这个 Integer的哈希码。
System.out.println(Integer.hashCode(7));//返回值为int的哈希码; 兼容Integer.hashCode() 。
System.out.println(Integer.max(2, 3));//返回两个 int的较大值,就像调用 Math.max一样 。
System.out.println(Integer.min(2, 3));//返回两个 int的较小值,就像调用 Math.min一样 。
System.out.println(Integer.sum(2, 3));//根据+运算符将两个整数相加。
System.out.println(a.toString());//Integer转String
System.out.println(Integer.toString(1));//int转String
Integer c=Integer.valueOf(5);//int转Integer
-
BigInteger
BigInteger a=new BigInteger("12345678987654321");
BigInteger b=new BigInteger("98765432123456789");
System.out.println(a.abs());//返回一个BigInteger,它的值是此BigInteger的绝对值。
System.out.println(a.max(b));//返回较大值
System.out.println(a.min(b));//返回较小值
System.out.println(a.add(b));//返回值为 (this + val)
System.out.println(b.subtract(a));//返回值为 (this - val) 。
System.out.println(a.multiply(b));//返回值为 (this * val) 。
System.out.println(b.divide(a));//返回值为 (this / val) 。
System.out.println(a.pow(5));//返回a的五次方
System.out.println(a.compareTo(b));//将此BigInteger与指定的BigInteger进行比较。
System.out.println(a.doubleValue());//将此BigInteger转换为 double 。
System.out.println(a.floatValue());//将此BigInteger转换为 float 。
System.out.println(a.intValue());//将此BigInteger转换为 int 。
System.out.println(a.longValue());//将此BigInteger转换为 long 。
System.out.println(a.hashCode());//返回此BigInteger的哈希码。
System.out.println(a.bitLength());//返回此BigInteger的最小二进制补码表示中的位数, 不包括符号位。
二.浮点数类
-
Float
Float a=new Float(2.2);
Float b=new Float(5.5);
System.out.println(Float.compare(1.1F, 2.2F));//比较两个指定的 float值。
System.out.println(a.compareTo(b));//数字比较两个 Float对象。
System.out.println(a.hashCode());//返回此 Float对象的哈希码。
System.out.println(Float.hashCode(1.1F));//返回一个float值的哈希码; 兼容Float.hashCode() 。
System.out.println(a.intValue());//Float转int
System.out.println(Float.max(1.1F, 2.2F));//返回两个 float的较大值,就像调用 Math.max
System.out.println(Float.min(1.1F, 2.2F));//返回两个 float的较小值,就像调用 Math.min
System.out.println(Float.sum(1.1F, 2.2F));//根据+运算符将两个 float值一起添加。
String str=a.toString();
System.out.println(str);//Float转String
-
Double
与Float相仿具体查阅JAVA官方文档
-
BigDecimal
与BigInteger相仿具体查阅JAVA官方文档
三.随机数类(Random)
Random a=new Random();
System.out.println(a.nextInt());//生成int类型随机数
System.out.println(a.nextInt(100));//生成0-100间随机数
System.out.println(a.nextBoolean());//生成boolean类型随机数
System.out.println(a.nextDouble());//生成double类型随机数
System.out.println(a.nextFloat());//生成float类型随机数
System.out.println(a.nextLong());//生成long类型随机数
int[] b = a.ints(10).toArray();
for(int item:b) {
System.out.print(" "+item);
}//生成10个int范围内的随机数
四.数学类(Math)
System.out.println(Math.abs(9));//返回值为 int绝对值。 可传入double,float,long
System.out.println(Math.addExact(6, 5));//返回其参数的总和,如果结果溢出int,则抛出 int 。 long同理
//三角函数
System.out.println(Math.sin(3.3));//返回角度的三角正弦。
System.out.println(Math.cos(2.2));//返回角度的三角余弦。
System.out.println(Math.tan(5));//返回角度的三角正切。
System.out.println(Math.acos(0.5));//返回值的反余弦值; 返回的角度在0.0到pi的范围内。
System.out.println(Math.asin(0.5));//返回值的正弦值; 返回角度在pi / 2到pi / 2的范围内。
System.out.println(Math.atan(0.5));//返回值的反正切值; 返回角度在pi / 2到pi / 2的范围内。
System.out.println(Math.sqrt(4.0));//平方根
System.out.println(Math.log(99.99));//返回的自然对数(以 e为底) double值。
System.out.println(Math.pow(2.2, 3));//2.2的3次方
//四则运算,大小
System.out.println(Math.max(3, 9));//返回两个 int值中的较大值。 可传入double,float,long
System.out.println(Math.min(3, 9));//返回两个 int的较小值。 可传入double,float,long
System.out.println(Math.multiplyExact(3, 8));//返回参数的乘积,如果结果溢出int,则抛出 int 。可传入long