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 }
  • 相关阅读:
    WCF进行大数据传输时的相关配置(转)
    自定义绑定(转)
    菜鸟学TSQLSQL2005读书笔记1
    再别康桥英文及译文
    自定义绑定2
    我要读的书
    菜鸟学TSQLSQL2005读书笔记
    Bad Habbits
    实践测试驱动开发
    针对接口写测试用例
  • 原文地址:https://www.cnblogs.com/jiangjunwei/p/9201643.html
Copyright © 2011-2022 走看看