三角函数:

public static double sin (double radians)

public static double cos(double radians)
public static double tan(double radians)
public static double toRadians (double degree)
public static double toDegrees (double radians)
public static double asin (double a)
public static double acos (double b)
public static double atan (double a)
【sin、cos 和 tan 的参数都是以弧度为单位的角。asin、acos 和 atan 的返回值是在 -π/2 到 π/2 之间的一个弧度值。1度相当于 π/180 弧度,90 弧度相当于 π/2 弧度】例如:
Math.toDegrees ( Math.PI/2 )    returns  90.0
Math.toRadians ( 30 )    returns  π/6
Math.sin ( 0 )    returns  0.0
Math.sin ( Math.toRadians(270) )    returns -1.0
Math.sin ( Math.PI/6 )    returns  0.5
Math.sin ( Math.PI/2 )    returns  1.0
Math.cos ( 0 )    returns 1.0
Math.cos ( Math.PI/6 )    returns    0.866
Math.cos ( Math.PI/2 )    returns    0
Math.asin ( 0.5 )    returns   π/6

指数函数:
public static double exp ( double x )   【e^x】
public static double log ( double x )    【 ln x 】
public static double log10 (double x )    【 log10 (x) 】
public static double pow ( double a, double b )
public static double sqrt ( double x ) 
例如:
Math.exp ( 1 )    returns 2.71828
Math.log ( Math.E )    returns 1.0
Math.log10 ( 10 )    returns 1.0
Math.pow ( 2, 3 )    returns 8.0
Math.pow ( 3, 2 )    returns 9.0
Math.pow (3.5, 2.5 )    returns 22.91765
Math.sqrt ( 4 )    returns 2.0
Math.sqrt ( 10.5 )    returns 3.24

取整方法:
public static double ceil ( double x )  【向上取整】
public static double floor ( double x )    【向下取整】
public static double rint ( double x )    【取最接近的整数,如果有两个同样接近的整数(.5),就两个中随机取一个 】
public static int round ( float x )    /* Return (int)Math.floor (x + 0.5 ) */
public static long round ( double x )     /*  Return (long)Math.floor ( x + 0.5) */
例如:
Math.ceil ( 2.1 )      returns 3.0
Math.ceil ( 2.0 )      returns 2.0
Math.ceil ( -2.0 )     returns -2.0
Math.ceil ( -2.1 )     returns -2.0
Math.floor ( 2.1 )    returns 2.0
Math.floor ( 2.0 )    returns 2.0
Math.floor ( -2.0 )   returns -2.0
Math.floor ( -2.1 )   returns -3.0
Math.rint ( 2.1 )       returns 2.0
Math.rint ( -2.0 )      returns -2.0
Math.rint ( -2.1 )      returns -2.0
Math.rint ( 2.5 )       returns 2.0
Math.rint ( 3.5 )       returns 4.0
Math.rint ( -2.5 )     returns -2.0
Math.round ( 2.6f ) returns 3  // returns  int
Math.round ( 2.0 )  returns 2  // returns  long
Math.round ( -2.0f ) returns -2  
Math.round ( -2.6 ) returns -3


重载方法 abs 返回一个数(int、 long、 float、 double)的绝对值,如:
Math.abs ( -2.1 )   returns 2.1 ; Math 还有 max 和 min 方法,对比两个数

因为 0 <= Math.random( ) < 1.0 , 若需 0 ~ 50 个随机数,则是 ( int )( Math.random( )*(50 + 1))   
【记得 + 1】 ,随机小写字母是 ( char )( 'a' + Math.random( )*('z' - 'a' + 1) )

Math类常用方法(Java)的更多相关文章

  1. java基础-Math类常用方法介绍

    java基础-Math类常用方法介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Math类概念 Math 类包含用于执行基本数学运算的方法,如初等指数.对数.平方根和三角函 ...

  2. Java Math类(java.lang包)

    Math类包含用于执行基本数学运算的方法,其所有方法都是静态方法,所以使用该类中的方法时,可以直接使用类名.方法名,如: Math.round(); 运行结果:

  3. java Math类常用方法

    package com.niuke.test; public class MathDemo { public static void main(String args[]){ /** * abs求绝对 ...

  4. Java基础(39):数据的四舍五入、去整、产生随机数---Math类的应用

    使用 Math 类操作数据 Math 类位于 java.lang 包中,包含用于执行基本数学运算的方法, Math 类的所有方法都是静态方法,所以使用该类中的方法时,可以直接使用类名.方法名,如: M ...

  5. Java学习--使用 Math 类操作数据

    使用 Math 类操作数据 Math 类位于 java.lang 包中,包含用于执行基本数学运算的方法, Math 类的所有方法都是静态方法,所以使用该类中的方法时,可以直接使用类名.方法名,如: M ...

  6. 构造方法,重载,static,math类(java基础知识七)

    1.构造方法概述和格式 * A:构造方法概述和作用     * 给对象的数据(属性)进行初始化 * B:构造方法格式特点     * a:方法名与类名相同(大小也要与类名一致)     * b:没有返 ...

  7. Java学习笔记(5)--- Number类和Math 类,String类的应用,Java数组入门

    1.Number 和 Math 类: 在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型(int,double,float这些)的情形. 这种由编译器特别支持的包装称为装箱,所以当内置数 ...

  8. Java常用类(一)Math类和Random类

    一.Math类 Math类中有一些常用的数学函数,比较简单,不进行详细解释,仅举例说明: 1.绝对值和取整 import java.lang.Math; public class Mat { publ ...

  9. JAVA中使用使Math 类操作数据

    转自:https://www.imooc.com/code/2342 侵删! Math 类位于 java.lang 包中,包含用于执行基本数学运算的方法, Math 类的所有方法都是静态方法,所以使用 ...

随机推荐

  1. Sphinx Search 学习 (一)

    参考资料一:(中文)http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html (官方)http://sphinxsearch.com/doc ...

  2. 使用dreamweaver去掉文本中的空格和换行

    当我们从其他地方拷贝文本到网页,在html代码中会自动带有空格和换行,手动去掉很麻烦,今天试着用dreamweaver去了一下,方法如下: 1.点击Ctrl+F,打开“查找和替换”窗口 2‘见下图:

  3. Centos7 hostname重启失效

    /etc/hosts  文件如下 [root@god ~]# more /etc/hosts 127.0.0.1 localhost ::1 localhost localhost.localdoma ...

  4. 关于RSA加密算法的长度限制问题

    RSA是常用的非对称加密算法.近来有学生在项目中使用System.Security类库中的RSA加密算法时,出现了“不正确的长度”,这实际上是因为待加密的数据超长所致..net Framework中提 ...

  5. PHP分页代码

       }            <a href="fenye.php?page=<?php echo  <?php  }    <a href="fenye ...

  6. Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试

    Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试一.下载相关安装包 1.下载nginx最新版本(nginx1.3.13版之后才支持websocket协议) 下载地址 ...

  7. JSTL跳出<c:forEach>循环

    <c:forEach items="${consultPager.dataList }" var="consult"> <tr> < ...

  8. 痛苦的vsftpd配置

    1.下载安装:yum install vsftpd 2.添加用户和组(不一定要添加组) group -g 1010 customedname useradd -g customedname -d /h ...

  9. Java基础&笔试题

    这些题目是近期我参加过的笔试题和一些我在网上选的部分题,在这里做笔记,认真去学习,更好的应对后面的招聘.有错误欢迎指出. 一.Java基础部分 1.指针在任何情况下都可进行>,<,> ...

  10. OC基础--Xcode 模板修改和文档安装

    修改项目模板 项目模板就是创建工程的时候选择的某一个条目, Xcode会根据选择的条目生成固定格式的项目 如何修改项目模板 找到Xcode, 右键"显示包内容" 打开"/ ...