三角函数:

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. memcached 的简介、安装、命令

    一.memcached 概述 Memcache(内存,缓存) : 是一个高性能的分布式的内存对象缓存系统.通过在内存里维护一个巨大的hash表.(key=value) Hash表 key(键) val ...

  2. About “this” of Javascript

    the 4 point about This: 1.the use of Object methods 2.the use of constructors 3.the use of ordinary ...

  3. Apache多端口监听

    打开:config/httpd.conf 找到Listen 80 在下面增加你要监听的端口,修改后如下: Listen 80 Listen 81 重启apache服务器

  4. laravel cookie写入

            $cookie = cookie('cookie_name', 'value', 5);        $data = ['title'=>'hello world'];     ...

  5. Could not parse mapping document from input stream

    无法从输入流解析映射文档 1.定义的类名或属性名不对,如:*.hbm.xml文件中属性name对应的实体类name不一致.2.xml头文件中"http://www.hibernate.org ...

  6. cc1101 ASK发射模式

    cc1101 配置  433.919830Mhz  1.19948kBaud   199.951172  58.035714 #ifndef _CC1100_H_#define _CC1100_H_ ...

  7. MicroERP开发技术分享:vsFlexGrid、scriptControl实现工资表自定义列与表间关系计算

    开发大型的MIS系统,肯定是离不开第三方控件的,同时也要根据项目需要自己写几个. MicroERP共用了以下几个控件: 第三方商业控件: vsFlexGrid:大名鼎鼎的表格控件,不用多说,配合vsP ...

  8. C语言中内存对齐

    今天一考研同学问我一个问题,一个结构体有一个int类型成员和一个char类型成员,问我这个结构体类型占多少个字节,我直接编个程序给他看结果.这个结构体占八个字节,咦,当时我蛮纳闷的,一个int类型四个 ...

  9. 解决 主界面mainactivity 中fragment弹框把下面tab选项卡 顶上去的方案

     android:windowSoftInputMode="adjustPan"            android:configChanges="screenSize ...

  10. sqlserver 存储过程分页管理

    -- =============================================-- Author:  <Author:刘畅>-- Create date: <Cre ...