标签:java之math类
Math类概述及其成员方法
Math类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。
成员变量:
public static final double PI
pubilc static final double E
成员方法:
public static int abs(int a)//绝对值
public static double ceil(double a):向上取整
public static double floor(double a):向下取整
public static int max(int a,int b):最大值
public static double pow(double a,double b):a的b的次幂
public static double random():随机数[0,1)
public static long round(float a):四舍五入
public static double sqrt(double a):求正平方根
package cn; /** * Math:用于数学运算的类 * 成员变量: * public static final double PI * pubilc static final double E * 成员方法: * public static int abs(int a)//绝对值 * public static double ceil(double a):向上取整 * public static double floor(double a):向下取整 * public static int max(int a,int b):最大值 * public static double pow(double a,double b):a的b的次幂 * public static double random():随机数[0,1) * public static long round(float a):四舍五入 * public static double sqrt(double a):求正平方根 */ public class MathDemo { public static void main(String[] args) { //public static final double PI System.out.println(Math.PI);//3.141592653589793 //pubilc static final double E System.out.println(Math.E);//2.718281828459045 //public static int abs(int a)//绝对值 System.out.println(Math.abs(-1));//1 System.out.println(Math.abs(1));//1 //public static double ceil(double a):向上取整 System.out.println(Math.ceil(0.1));//1.0 System.out.println(Math.ceil(12.34));//13.0 System.out.println(Math.ceil(12.78));//13.0 //public static double floor(double a):向下取整 System.out.println(Math.floor(12.34));//12.0 System.out.println(Math.floor(12.78));//12.0 //public static int max(int a,int b):最大值 System.out.println(Math.max(12, 13));//13 //public static double pow(double a,double b):a的b的次幂 System.out.println(Math.pow(2, 3));//8.0 //public static round(float a):四舍五入 System.out.println(Math.round(4.5));//5 // public static double sqrt(double a):求正平方根 System.out.println(Math.sqrt(4));//2 } }
本文出自 “11831428” 博客,请务必保留此出处http://11841428.blog.51cto.com/11831428/1860502
标签:java之math类
原文地址:http://11841428.blog.51cto.com/11831428/1860502