JAVA基础(36)---Math

版权声明:如需转载请标明出处 https://blog.csdn.net/yj201711/article/details/83926978

与数学运算相关的Math:

Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。   三角函数

public static final double PI        //3.14159265358979323846;
public static final double E         // 2.7182818284590452354;


通过(6)方法产生的随机数是一个伪随机数,因为它是通过一种随机算法算出来的数。

public class MathDemo{
	public static  void  main(String[] args){
		double e = Math.E;
		System.out.println(e);
		Double pi = Math.PI;
		System.out.println(pi);
		double ran  = Math.random();//产生随机数 [0.0--1.0)
		System.out.println(ran);
		//需要产生一个1--3之间的随机整数:
		int ran2 =(int) (Math.random() * 3) + 1;
		System.out.println(ran2);
		System.out.println("------------------------");
		long i = Math.round(2.5);
		System.out.println(i);


	
	}
}

猜你喜欢

转载自blog.csdn.net/yj201711/article/details/83926978