System类常见方法和案例,大数处理,
- gc:运行垃圾回收机制System.gc();
-
package com.jshedu.arrays_;import java.util.Arrays;/*** @author 韩顺平* @version 1.0*/ public class System_ {public static void main(String[] args) {//exit 退出当前程序System.out.println("ok1"); // //老韩解读 // //1. exit(0) 表示程序退出 // //2. 0 表示一个状态 , 正常的状态 // System.exit(0);// // System.out.println("ok2");//arraycopy :复制数组元素,比较适合底层调用,// 一般使用Arrays.copyOf完成复制数组int[] src={1,2,3};int[] dest = new int[3];// dest 当前是 {0,0,0}//老韩解读//1. 主要是搞清楚这五个参数的含义//2.// 源数组// * @param src the source array.// srcPos: 从源数组的哪个索引位置开始拷贝// * @param srcPos starting position in the source array.// dest : 目标数组,即把源数组的数据拷贝到哪个数组// * @param dest the destination array.// destPos: 把源数组的数据拷贝到 目标数组的哪个索引// * @param destPos starting position in the destination data.// length: 从源数组拷贝多少个数据到目标数组// * @param length the number of array elements to be copied.System.arraycopy(src, 0, dest, 0, src.length);// int[] src={1,2,3};System.out.println("dest=" + Arrays.toString(dest));//[1, 2, 3]//currentTimeMillens:返回当前时间距离1970-1-1 的毫秒数// 老韩解读:System.out.println(System.currentTimeMillis());} }
注意参数的意思
-
BigInteger适合保存比较大的整数
-
package com.jshedu.Math_;import java.math.BigInteger;/*** @author jia* @version 1.0*/ public class BigInteger_ {public static void main(String[] args) {//当我们编程中,需要处理很大的整数,long 不够用//可以使用BigInteger的类来搞定 // long l = 23788888899999999999999999999l; // System.out.println("l=" + l);BigInteger bigInteger = new BigInteger("23788888899999999999999999999");BigInteger bigInteger2 = new BigInteger("10099999999999999999999999999999999999999999999999999999999999999999999999999999999");System.out.println(bigInteger);//老韩解读//1. 在对 BigInteger 进行加减乘除的时候,需要使用对应的方法,不能直接进行 + - * ///2. 可以创建一个 要操作的 BigInteger 然后进行相应操作BigInteger add = bigInteger.add(bigInteger2);System.out.println(add);//加BigInteger subtract = bigInteger.subtract(bigInteger2);System.out.println(subtract);//减BigInteger multiply = bigInteger.multiply(bigInteger2);System.out.println(multiply);//乘BigInteger divide = bigInteger.divide(bigInteger2);System.out.println(divide);//除} }
加减乘除使用相应的方法
-
-
BigDecimal适合保存精度更高的浮点型(小数)
-
package com.jshedu.Math_;import java.math.BigDecimal;/*** @author jia* @version 1.0*/ public class BigDecimal_ {public static void main(String[] args) {//当我们需要保存一个精度很高的数时,double 不够用//可以是 BigDecimal // double d = 1999.11111111111999999999999977788d; // System.out.println(d);BigDecimal bigDecimal = new BigDecimal("1999.11123232332");BigDecimal bigDecimal2 = new BigDecimal("3");System.out.println(bigDecimal);//老韩解读//1. 如果对 BigDecimal进行运算,比如加减乘除,需要使用对应的方法//2. 创建一个需要操作的 BigDecimal 然后调用相应的方法即可System.out.println(bigDecimal.add(bigDecimal2));System.out.println(bigDecimal.subtract(bigDecimal2));//减System.out.println(bigDecimal.multiply(bigDecimal2));//System.out.println(bigDecimal.divide(bigDecimal2));////可能抛出异常ArithmeticException可能除不尽//在调用divide 方法时,指定精度即可. BigDecimal.ROUND_CEILING//如果有无限循环小数,就会保留 分子 的精度1999.11123232332System.out.println(bigDecimal.divide(bigDecimal2, BigDecimal.ROUND_CEILING));}//666.37041077444 }
调用方法进行加减乘除
-