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
        }
  • 相关阅读:
    情书2
    情书1
    python_数据分析_正态分布
    python3调用R语言干货
    常见混淆名词
    PID算法图形 python
    A*寻路算法 python实现
    用tensorflow object detection api做手势识别
    tf识别非固定长度图片ocr(数字+字母 n位长度可变)- CNN+RNN+CTC
    tf识别固定长度验证码图片ocr(0到9 4位)- CNN方式
  • 原文地址:https://www.cnblogs.com/wyc1991/p/9011510.html
Copyright © 2011-2022 走看看