计算数学函数 Math 中的sin cos log 等数学方法 以及Random随机数的生成
import java.util.Random;
public class Elapsed {
public static void main(String args[]) {
double d=0;
Random random=new Random();
//Math类的使用
System.out.println("sin函数: "+Math.sin(d));
System.out.println("cos函数: "+Math.cos(d));
System.out.println("log函数: "+Math.log(d));
// 随机数函数
System.out.println("Randm函数: "+Math.random());
//random类的使用
System.out.println("随机整数: "+ random.nextInt());
System.out.println("随机大于0小于10的整数: "+random.nextInt(10));
System.out.println("随机布尔值: "+random.nextBoolean());
System.out.println("随机双精度: "+random.nextDouble());
System.out.println("随机浮点型: "+random.nextFloat());
}
}
运行结果: