zoukankan      html  css  js  c++  java
  • JAVA Math常用方法

    public class Test {
    
        public static void main(String[] args) {
            /**
             * Math.sqrt()//计算平方根
             * Math.cbrt()//计算立方根
             * Math.pow(a,b)//计算a的b次方
             * Math.max( , )//计算最大值
             * Math.min( , )//计算最小值        
             */
            
            System.out.println(Math.sqrt(9));//3.0
            System.out.println(Math.cbrt(8));//2.0
            System.out.println(Math.pow(2, 3));//8.0
            System.out.println(Math.max(2.4, 3.8));//3.8
            System.out.println(Math.min(2.5, 8.4));//2.5
            
            /**
             * Math.abs()//求绝对值
             */
            
            System.out.println(Math.abs(-1.5));//1.5
            System.out.println(Math.abs(10.5));//10.5
            
            /**
             * Math.floor()//向下取整,floor是地板的意思;
             * Math.ceil()//向上取整,ceil是天花板的意思;
             * Math.round()//四舍五入取整;
             * Math.rint()//也是四舍五入取整;但.5时会取偶数;
             */
            
            System.out.println(Math.floor(10));//10.0
            System.out.println(Math.floor(10.5));//10.0
            System.out.println(Math.floor(10.7));//10.0
            System.out.println(Math.ceil(11.2));//12.0
            System.out.println(Math.round(10.5));//11
            System.out.println(Math.rint(10.5));//10.0
            
            /**
             * Math.random()//取0到1之间随机的数(包括0但不包括1);
             */
            
            System.out.println(Math.random());//0.0883798391075995
            System.out.println(Math.random() * 2);//0.35747170018174357
            System.out.println(Math.random() + 10);//10.405883407565078
        }
  • 相关阅读:
    vue中使用axios
    vue中报错Do not use built-in or reserved HTML elements as component id details
    人月神话阅读笔记01
    学习进度周总结(第五周)
    石家庄地铁系统开发(java web版)(一)
    梦断代码阅读笔记03
    二维数组求最大子数组
    学习进度周总结
    梦断代码阅读笔记02
    二维数组
  • 原文地址:https://www.cnblogs.com/wyc1991/p/9011510.html
Copyright © 2011-2022 走看看