public class MathDemo {
public static void main(String[] args) {
double d = Math.ceil(12.34); // 返回大于等于指定数据的最小整数
System.out.println(d);
double d1 = Math.floor(12);// 返回小于等于指定数据的最大整数
System.out.println(d1);
long l = Math.round(12.54);// 四舍五入
System.out.println(l);
double d2 = Math.pow(2, 3);// 幂运算
System.out.println(d2);
for (int i = 0; i < 10; i++) {
double d3 = Math.random();// [0,1)随机产生 伪随机数
System.out.println(d3);
}
//随机生成[1,10]
for (int i = 0; i < 10; i++) {
int d3 = (int) (Math.random() * 10 + 1);// [0,1)随机产生 伪随机数
System.out.println(d3);
}
//随机生成[1,10]
Random r = new Random();
for (int i = 0; i < 10; i++) {
int d3 = r.nextInt(10) + 1;
System.out.println(d3);
}
}
}