Java's Math class

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45778981/article/details/102755051

Java's Math class

import static java.lang.Math.*;//加上这个包以下的Math均可省略   //静态导入
public class testMath {
	public static void main(String[] args) {
		System.out.println("绝对值 "+Math.abs(23)+"\t"+Math.abs(-23)+"\t"+Math.abs(0));
		System.out.println("向上取整再转double "+Math.ceil(23.00001)+"\t"+Math.ceil(-9.99999));
		System.out.println("向下取整再转double "+Math.floor(23.99999)+"\t"+Math.floor(-23.00001));
		System.out.println("最值:"+Math.max(20, 10)+"\t"+Math.min(3,40));		
		System.out.println("5的2次方  "+Math.pow(5, 2));
		System.out.println("随机数(0-1)"+Math.random());
		int ran=(int) (Math.random()*9000);//四位数随机数
		System.out.println("四舍五入"+Math.round(34.567)+"\t"+Math.round(34.234));
		System.out.println("开方"+Math.sqrt(4));
		
	}
}

Guess you like

Origin blog.csdn.net/weixin_45778981/article/details/102755051