Math类的使用

来源:互联网 发布:java 用户登录次数 编辑:程序博客网 时间:2024/05/21 14:59
实验任务
计算数的绝对值,两个值比较大小,取0~1之间随机数


实验要求
计算-10.4的绝对值
比较55, -10两个数哪个小
比较0.0, -0.0两个数哪个大

取0~1之间随机数

public class TestMath {
public static void main(String[] args) {
System.out.println("计算-10.4的绝对值:"+Math.abs(-10.4));
System.out.println("比较55, -10两个数哪个小:"+Math.min(55, -10));
System.out.println("比较0.0, -0.0两个数哪个大:"+Math.max(0.0, -0.0));
System.out.println("取0~1之间随机数:"+Math.random());
}
}

0 0
原创粉丝点击