package MathApi;
import java.util.Random;
public class MathApiDemo {
public static void main(String[] args) {
/*
* Math:提供了操作数学运算的方法,都是静态的
*
* 常用的方法:
* cell():返回大于参数的最小整数
* floor():返回小于参数的最大整数
* round():返回四舍五入的整数
* pow(a,b):a的b次方
* random():返回随机数
*/
double d1=Math.ceil(12.56);
double d2=Math.floor(12.56);
double d3=Math.round(12.56);
sop("d1="+d1);
sop("d2= "+d2);
sop("d3="+d3);
//double d=Math.pow(10,2);
//sop(d);
Random r=new Random();
for(int i=0;i<10;i++) {
//double d=(int)(r.nextDouble()*6+1);
int d=r.nextInt(6);
System.out.println(d);
}
/*for(int i=0;i<10;i++) {
double d=Math.random();
System.out.println(d);
}*/
}
public static void sop(String string) {
System.out.println(string);
}
}
Java MathApi
最新推荐文章于 2024-06-15 16:32:53 发布