一.Math类的常用方法
Math类方法 | 说明 |
---|---|
abs(double a) | 返回a的绝对值 |
max (double a,double b) | 返回a.b的最大值 |
min (double a,double b) | 返回a.b的最小值 |
random() | 产生一个0到1的随机数 |
pow (double a,double b) | 返回a的b次幕 |
sqrt (double a) | 返回a的平方根 |
log(double a) | 返回a的对数 |
sin(double a) | 返回a的正弦值 |
asin(double a) | 返回反正弦值 |
二.BigInteger类(提供任意精度的整数运算)
构造方法:public BigInteger(String val)返回一个十进制的BigInteger对象
BigInteger类对象可以调用相应的方法来进行和差积商余运算,还有比较大小运算。
3.Random类
package train;
import java.util.Random;
public class Test{
public static void main(String[] args) {
double a=Math.random();//返回0-1之间的随机数,不包括0和1
System.out.println(a);
int b=(int)(Math.random()*100)+1;//返回1-100之间的随机数,包括1和100
System.out.println(b);
Random random1=new Random();//无参构造函数
int c=random1.nextInt();
System.out.println(c);
int d=random1.nextInt(100);//随机得到一个0至100的随机数,但不包括100,100是上限,种子为当前系统时间的毫秒数
System.out.println(d);
Random random2=new Random(100);//有参构造函数,设定种子为100,对于种子相同的随机数对象,生成的随机苏序列是一样的
int e=random2.nextInt(7);
System.out.println(e);
Random random3=new Random();
boolean f= random3.nextBoolean();//随机得到一个boolean值
System.out.println(f);
}
}