zoukankan      html  css  js  c++  java
  • java之Math类

     1 public class Demo1_Math {
     2 
     3     /*
     4      * Math类包含用于执行基本数学运算的方法,如:指数、对数、平方根等
     5      * Math中的所有方法都是静态的,构造方法是私有的
     6      * public static int abs(int a)               求一个数的绝对值
     7      * public static double ceil(double a)        向上取整,返回一个double值
     8      * public static double floor(double b)       向下取整,返回一个double值 
     9      * public static int max(int a, int b)        取两个之中的大的值    min同max类似,取最小值
    10      * public static int pow(double a, double b)  对一个double值做幂运算
    11      * public static double random()              取一个[0.0,1.0)之间的double的随机数
    12      * public static int round(float a)           四舍五入
    13      * public static double sqrt(double a)        对一个double数开平方
    14      */
    15     public static void main(String[] args) {
    16         System.out.println(Math.abs(-10));
    17         System.out.println(Math.ceil(12.7));
    18         System.out.println(Math.floor(12.6));
    19         System.out.println(Math.max(1, 9));
    20         System.out.println(Math.pow(6.0, 2.0));
    21         System.out.println(Math.random());
    22         System.out.println(Math.round(3.15));
    23         System.out.println(Math.sqrt(9));
    24         /*
    25          * 运行结果如下:
    26          *  10
    27             13.0
    28             12.0
    29             9
    30             36.0
    31             0.2989099810206127
    32             3
    33             3.0
    34          */
    35     }
    36 }
  • 相关阅读:
    Windows UI自动化测试的XPATH实现
    Laravel修炼:服务容器绑定与解析
    swoole之memoryGlobal内存池分析
    Go语言的前景分析
    thinkphp5 编辑时 唯一验证 解决办法
    GIT配置多用户
    PHP 数组
    PHP 变量作用域
    PHP 使用 Swoole
    欢迎使用CSDN-markdown编辑器
  • 原文地址:https://www.cnblogs.com/jiangjunwei/p/9201643.html
Copyright © 2011-2022 走看看