zoukankan      html  css  js  c++  java
  • 【Java】【常用类】Math 数学类

    一些常用的数学计算方法

    public class MathTest {
        public static void main(String[] args) {
            int a = -10;
    
            // 获取绝对值
            int abs = Math.abs(a);
    
            // 三角函数
    
            // 求平方根
            double sqrt = Math.sqrt(4);
            System.out.println(sqrt);
    
            // 求幂 也就是次方根  2的63次幂
            double pow = Math.pow(2, 63);
            System.out.println(pow);
    
            // 自然对数
            double log = Math.log(1000);
            System.out.println(log);
    
            // 求最大最小 Math.max(a,b) Math.min(a,b)
    
            // 随机数 范围 0.0 - 1.0
            double random = Math.random();
            System.out.println(random);
    
            // 四舍五入 long round(double a)
    
            // 向上取整 只要0.1就取1 Math.ceil(double a)
            // 向下取整 只要0.9就取0 Math.floor(double a)
            
        }
    }
  • 相关阅读:
    记账本开发第一天-补
    20200418-补
    20200411-补
    20200404-补
    20200328-补
    暴力解N皇后
    nN皇后递归
    Hanoi汉诺塔非递归栈解
    Hanoi汉诺塔递归
    JMMjmm模型
  • 原文地址:https://www.cnblogs.com/mindzone/p/12736275.html
Copyright © 2011-2022 走看看