zoukankan      html  css  js  c++  java
  • Java07-Math类的常用方法

    public class test_math {
    public static void main(String[] args) {
        //圆周率
        System.out.println("圆周率PI:"+Math.PI);
        //向上取整
        System.out.println("ceil天花板-9.1向上取整:"+Math.ceil(9.1));  //输出10.0
        //向下取整
        System.out.println("floor地板-9.8向下取整:"+Math.floor(9.8));//输出9.0
        //2个数中最大的
        System.out.println("2个数中最大的是:"+Math.max(10, 9));
        //2个数中最小的
        System.out.println("2个数中最小的是:"+Math.min(111, 999));
       //随机数 greater than or equal to 0.0 and less than 1.0
        System.out.println("大于等于0小于1的随机数-1:"+Math.random());
        System.out.println("大于等于0小于1的随机数-2:"+Math.random());
        //开平方
        System.out.println("9开平方:"+Math.sqrt(9.0));
        System.out.println("16开平方:"+Math.sqrt(16.0));
        //求幂(某一个数的n次方)
        System.out.println("2的4次方:"+Math.pow(2, 4));
        System.out.println("4的2次方:"+Math.pow(4, 2));
        //立方根
        System.out.println("9的立方根:"+Math.cbrt(9));
        System.out.println("27的立方根:"+Math.cbrt(27));
        //除数-向下
        System.out.println("22/10的商为:"+Math.floorDiv(22, 10));
        System.out.println("29/10的商为:"+Math.floorDiv(29, 10));
        //余数
        System.out.println("12除以10的余数为:"+Math.floorMod(12, 10));
        System.out.println("20除以17的余数为:"+Math.floorMod(20, 17));
        
    }
    }

    输出:

    圆周率PI:3.141592653589793
    ceil天花板-9.1向上取整:10.0
    floor地板-9.8向下取整:9.0
    2个数中最大的是:10
    2个数中最小的是:111
    大于等于0小于1的随机数-1:0.08284938685079868
    大于等于0小于1的随机数-2:0.7560700046216918
    9开平方:3.0
    16开平方:4.0
    2的4次方:16.0
    4的2次方:16.0
    9的立方根:2.080083823051904
    27的立方根:3.0
    22/10的商为:2
    29/10的商为:2
    12除以10的余数为:2
    20除以17的余数为:3
  • 相关阅读:
    使用Distinct()内置方法对List集合的去重 问题
    TCP连接与HTTP请求
    ASP.NET MVC 使用 Authorize 属性过滤器验证用户是否已登录
    C#进阶系列——WebApi 跨域问题解决方案:CORS
    关于设计模式的六大原则
    C# WebApi 接口传参详解
    数据库数据流量太大-问题诊断
    docker的build生成镜像和启动container
    docker生成dotnet core镜像
    NET Core 源码浏览站点工具
  • 原文地址:https://www.cnblogs.com/eosclover/p/13520191.html
Copyright © 2011-2022 走看看