eg: double pi = Math.PI;
System.out.println(pi);
eg: double e = Math.E;
System.out.println(e);
eg: double abs = Math.abs(-3.75);
System.out.println(abs);
eg: double ceil = Math.ceil(3.1579);
System.out.println(ceil);
eg: double floor = Math.floor(3.1579);
System.out.println(floor);
eg: double max = Math.max(3.14, 2.7);
System.out.println(max);
eg: double min = Math.min(3.14, 2.7);
System.out.println(min);
eg: double pow = Math.pow(2, 10);
System.out.println(pow);
eg: int random = (int) (Math.random()*100);————范围:0-99
System.out.println(random);
eg: long round = Math.round(3.14);
System.out.println(round);
eg: double sqrt = Math.sqrt(4);
System.out.println(sqrt);
eg: Random r = new Random(0L);———————— 填入nL
eg: Random r = new Random();
int i = r.nextInt();
System.out.println(i);————产生一个随机数,范围为int范围
eg: Random r = new Random();
int i = r.nextInt(100);
System.out.println(i);————产生一个随机数,范围为0-99
eg: byte[] bytes = new byte[20];
r.nextBytes(bytes);
System.out.println(Arrays.toString(bytes));
————输出:[-71, -98, -117, -4, 9, 86, 95, -117, 36, -52, 67, -10, -73, 62, -54, -2, 22, 63, -12, 44]
import java.io.InputStream;
import java.io.PrintStream;
public class demo {
public static void main(String[] args) {
方法一:
InputStream in = System.in;
//in “标准”输入流。此流已打开并准备提供输入数据。通常,此流对应于键盘输
PrintStream out = System.out;
//out “标准”输出流。此流已打开并准备接受输出数据。通常,此流对应于显示器
out.println("abcde");
方法二:
System.out.println("abcde"); //链式编程
}
}
eg: int[] ints = new int[20]; ————在堆内存开辟空间
for (int i = 0; i < ints.length; i++) {
System.out.println(ints[i]);
}
//若内存不够用
ints = null; ——————方法一:手动置空
System.gc(); ——————方法二:调用垃圾回收器(回收时间不确定)
0 为正常退出 非0为 异常退出
eg: System.exit(0); ————————退出,不运行下面的程序
eg: 获取从1970 0101 00:00:00到当前时间的间隔毫秒值
long start = System.currentTimeMillis();
for (int i = 0; i < 200000; i++) {
System.out.println(i);
}
long end = System.currentTimeMillis();
System.out.println("耗时:"+(end-start)+"毫秒");
eg: BigDecimal bd1 = new BigDecimal(9.141596);
BigDecimal bd2 = new BigDecimal(6.256478);
BigDecimal add = bd1.add(bd2);
System.out.println(add);————输出:15.39807400000000026096813598996959626674652099609375
eg: BigDecimal bd1 = new BigDecimal(9.141596);
BigDecimal bd2 = new BigDecimal(6.256478);
BigDecimal subtract = bd1.subtract(bd2);
System.out.println(subtract);————输出:2.88511799999999940524730845936574041843414306640625
eg: BigDecimal bd1 = new BigDecimal(9.141596);
BigDecimal bd2 = new BigDecimal(6.256478);
BigDecimal multiply = bd1.multiply(bd2);
System.out.println(multiply);————输出:57.1941942588880028671691827639732959938683725950761308170870733658119888787041418254375457763671875
eg: BigDecimal bd3 = new BigDecimal(9);
BigDecimal bd4 = new BigDecimal(3);
BigDecimal divide = bd3.divide(bd4);
System.out.println(divide);————输出:3
roundingMode 取舍模式 比如四舍五入
eg: BigDecimal bd1 = new BigDecimal(9.141596);
BigDecimal bd2 = new BigDecimal(6.256478);
BigDecimal divide1 = bd1.divide(bd2, 30,BigDecimal.ROUND_CEILING);
System.out.println(divide1);————输出:1.461140916662697320751925452620