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

    Math类概述

    Math类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。

    成员方法

    public static int abs(int a) 取绝对值
    public static double ceil(double a) 向上取整,结果是一个double
    public static double floor(double a) 向下取整,结果是一个double
    public static int max(int a,int b) 取两个数的最大值
    public static int min(int a,int b) 取两个数的最小值
    public static double pow(double a,double b) 取a的b次幂
    public static double random() 取随机数
    public static int round(float a) 四舍五入
    public static double aqrt(double a) 开平方

    public class test {
        public static void main(String[] args) {
            
            System.out.println(Math.PI);
            System.out.println(Math.E);
            System.out.println(Math.abs(-10));
            System.out.println(Math.ceil(3.8));
            System.out.println(Math.floor(3.8));
            System.out.println(Math.max(99, 100));
            System.out.println(Math.min(99, 100));
            System.out.println(Math.pow(2, 3));
            System.out.println(Math.random());
            System.out.println(Math.sqrt(16));
        }
        
    }
    输出:
    3.141592653589793
    2.718281828459045
    10
    4.0
    3.0
    100
    99
    8.0
    0.6447801029013275
    4.0
    
    
    
  • 相关阅读:
    hdu 4302 Holedox Eating 夜
    poj 1947 Rebuilding Roads 夜
    hdu 4303 Hourai Jeweled 夜
    poj 1286 Necklace of Beads 夜
    poj 2057 The Lost House 夜
    hdu 4301 Divide Chocolate 夜
    poj 3140 Contestants Division 夜
    BOM(二)
    Str的方法
    求出字符窜的字母的个数
  • 原文地址:https://www.cnblogs.com/bbn0111/p/7505803.html
Copyright © 2011-2022 走看看