Math类的概述和使用
-概述:Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数
-成员方法:
* public static int abs(int a) //返回a的绝对值 * public static double ceil(double a) //向上取整,返回一个大于a的最小double值 ceil - 天花板 * public static double floor(double a) //向下取整,返回一个小于a的最大double值 floor - 地板 * public static int max(int a,int b) min自学 //返回a,b中的较大的那个数 * public static double pow(double a,double b) //返回a的b次幂 * public static double random() //返回带正号的double值,该值在0.0-1.0之间,且不为0或1 * public static int round(float a) //返回最接近a的int数 * public static double sqrt(double a) //返回正确舍入的a的正平方根
57.Random类的概述和使用
-概述:此类用于产生随机数如果用相同的种子创建两个 Random 实例
-构造方法:
* public Random() * public Random(long seed) //使用单个long种子创建新的随机数生成器
-成员方法:
* public int nextInt() // 返回下一个伪随机数,它是此随机数生成器的序列中均匀分布的 int 值 * public int nextInt(int n) //返回一个伪随机数,它是取自此随机数生成器序列的在 0(包括)和指定值(不包括)之间均匀分布的 int 值
58.System类的概述和使用
-概述:System 类包含一些有用的类字段和方法它,不能被实例化(构造方法私有)
-成员方法:
* public static void gc() //运行垃圾回收器 * public static void exit(int status) //终止当前正在运行的java虚拟机 * public static long currentTimeMillis() //返回以毫秒为单位当前时间(当前时间与协调世界时1970年1月1日午夜之间的时间差) * pubiic static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) //从指定原数组复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束
59.BigInteger类的概述和使用
-概述:可以让超过Integer范围内的数据进行运算
-构造方法:* public BigInteger(String val) //将字符串转换为BigInteger类
-成员方法:
* public BigInteger add(BigInteger val) //+ * public BigInteger subtract(BigInteger val) //- * public BigInteger multiply(BigInteger val) //* * public BigInteger divide(BigInteger val) //除 * public BigInteger[] divideAndRemainder(BigInteger val) //返回包含 (this / val)后跟(this % val)的两个BigInteger的数组
package javademo; import java.math.BigInteger; public class demo7 { public static void main(String[] args) { BigInteger b1 = new BigInteger("100"); BigInteger b2 = new BigInteger("2"); System.out.println("和:"+b1.add(b2)); System.out.println("差:"+b1.subtract(b2)); System.out.println("积:"+b1.multiply(b2)); System.out.println("商:"+b1.divide(b2)); BigInteger[] b3 = b1.divideAndRemainder(b2); //返回b1/b2的值和b1