您的位置:首页 > 编程语言 > Java开发

java 基础,Math类基本方法总结

2017-03-30 10:34 155 查看
package com.zhengyanfeng.math;

public class MathTest {

public static void main(String[] args) {

//javaMath类基本方法
System.out.println(Math.abs(-10)); //求一个数的绝对值
System.out.println(Math.ceil(12.3)); //对一个数向上取整
System.out.println(Math.floor(12.3)); //对一个数向下取整
System.out.println(Math.max(55, 66)); //求两个数的最大值
System.out.println(Math.min(55, 66)); //求两个数的最小值
System.out.println(Math.pow(2, 3)); //求2的3次方
System.out.println(Math.random()); //求0.0到1.0之间的一个随机数
System.out.println(Math.round(16.5)); //求一个数的四舍五入值
System.out.println(Math.sqrt(2)); //求一个数的平方根
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  math
相关文章推荐