数学相关常用类
- 和数学相关的就去Math类
- Random专门做随机数
- UUID是唯一随机数
- BigInteger大整数:比long大,-2的63次方 ~ 2的63次方-1
- DecimalFormat格式化小数位数的类
package com.li.changGe.commonlyusedClass;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.UUID;
public class MathRelatedDemo01 {
public static void main(String[] args) {
decimalFormat();
}
public static void mathTest(){
int num = Math.abs(-1);
double result = Math.PI;
result = Math.E;
result = Math.ceil(10.5);
result = Math.floor(10.4);
result = Math.rint(1.5);
result = Math.round(10.5);
num = Math.max(10,20);
result = Math.pow(10,3);
result = Math.sqrt(9);
result = Math.random()*6+5;
}
public static void randomTest(){
Random random = new Random(-1);
int num = random.nextInt(10);
double v = random.nextDouble();
boolean b = random.nextBoolean();
}
public static void UUIDTest(){
UUID uuid = UUID.randomUUID();
}
public static void bigIntegerTest(int num){
BigInteger bigInteger = new BigInteger("1");
for (int i = 1; i <= num; i++) {
bigInteger = bigInteger.multiply(new BigInteger(i+""));
}
System.out.println(bigInteger);
}
public static void decimalFormat(){
DecimalFormat decimalFormat = new DecimalFormat("000.##");
String format = decimalFormat.format(13.8999);
System.out.println(format);
}
}