import java.text.SimpleDateFormat;
import java.util.Date; public class Test4 { public static void main(String[] args) {
/**
*Math.sqrt()//计算平方根
*Math.cbrt()//计算立方根
*Math.pow(a, b)//计算a的b次方
*Math.max( , );//计算最大值
*Math.min( , );//计算最小值
*/ System.out.println(Math.sqrt(16)); //4.0
System.out.println(Math.cbrt(8)); //2.0
System.out.println(Math.pow(3,2)); //9.0
System.out.println(Math.max(2.3,4.5));//4.5
System.out.println(Math.min(2.3,4.5));//2.3 /**
* abs求绝对值
*/
System.out.println(Math.abs(-10.4)); //10.4
System.out.println(Math.abs(10.1)); //10.1 /**
* ceil天花板的意思,就是返回大的值
*/
System.out.println(Math.ceil(-10.1)); //-10.0
System.out.println(Math.ceil(10.7)); //11.0
System.out.println(Math.ceil(-0.7)); //-0.0
System.out.println(Math.ceil(0.0)); //0.0
System.out.println(Math.ceil(-0.0)); //-0.0
System.out.println(Math.ceil(-1.7)); //-1.0 /**
* floor地板的意思,就是返回小的值
*/
System.out.println(Math.floor(-10.1)); //-11.0
System.out.println(Math.floor(10.7)); //10.0
System.out.println(Math.floor(-0.7)); //-1.0
System.out.println(Math.floor(0.0)); //0.0
System.out.println(Math.floor(-0.0)); //-0.0 /**
* random 取得一个大于或者等于0.0小于不等于1.0的随机数
*/
System.out.println(Math.random()); //小于1大于0的double类型的数
System.out.println(Math.random()*2);//大于0小于1的double类型的数
System.out.println(Math.random()*2+1);//大于1小于2的double类型的数 /**
* rint 四舍五入,返回double值
* 注意.5的时候会取偶数 异常的尴尬=。=
*/
System.out.println(Math.rint(10.1)); //10.0
System.out.println(Math.rint(10.7)); //11.0
System.out.println(Math.rint(11.5)); //12.0
System.out.println(Math.rint(10.5)); //10.0
System.out.println(Math.rint(10.51)); //11.0
System.out.println(Math.rint(-10.5)); //-10.0
System.out.println(Math.rint(-11.5)); //-12.0
System.out.println(Math.rint(-10.51)); //-11.0
System.out.println(Math.rint(-10.6)); //-11.0
System.out.println(Math.rint(-10.2)); //-10.0 /**
* round 四舍五入,float时返回int值,double时返回long值
*/
System.out.println(Math.round(10.1)); //10
System.out.println(Math.round(10.7)); //11
System.out.println(Math.round(10.5)); //11
System.out.println(Math.round(10.51)); //11
System.out.println(Math.round(-10.5)); //-10
System.out.println(Math.round(-10.51)); //-11
System.out.println(Math.round(-10.6)); //-11
System.out.println(Math.round(-10.2)); //-10 }
}

  

Java 中Math常用方法的更多相关文章

  1. java中Math常用方法

    public class Demo{ public static void main(String args[]){ /** *Math.sqrt()//计算平方根 *Math.cbrt()//计算立 ...

  2. Java中的常用方法

    Java中的常用方法 第一章 字符串 1.获取字符串的长度:length() 2.判断字符串的前缀或后缀与已知字符串是否相同    前缀 startsWith(String s).后缀 endsWit ...

  3. JavaScript中Math常用方法

    title: JavaScript中Math常用方法 toc: false date: 2018-10-13 12:19:31 Math.E --2.718281828459045,算数常量e Mat ...

  4. Java中math类的常用函数

    Java中math类的常用函数 在 Java 中 Math 类封装了常用的数学运算,提供了基本的数学操作,如指数.对数.平方根和三角函数等 只要在源文件的顶部加上下面这行代码就不必在数学方法名和常量名 ...

  5. Java 中String常用方法

    java中String的常用方法 1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len ...

  6. Java中String常用方法

    java中String的常用方法1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len= ...

  7. java的math常用方法

    鉴于java求整时欲生欲死,整理常用math如下: 1: java取整 a:floor向下取整 用法:Math.floor(num) Math.floor(1.9)//1               ...

  8. Java中Math类的常用方法

    public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println( ...

  9. java 中Math 的常用方法

    public class Demo{ public static void main(String args[]){ /** *Math.sqrt()//计算平方根 *Math.cbrt()//计算立 ...

随机推荐

  1. String 字符串的==和eqauls区别

    1.对于基本类型来说,==比较的是数据的值,equals方法也是数据的值: 对于引用类型来说,==比较的是引用的地址,equals方法比较的是对象的内容. 2.String是引用类型,用“=”创建字符 ...

  2. Linux下使用nextcloud搭建个人网盘

    市面上有那么多的网盘服务提供商,为什么还要自己搭建网盘呢?主要有以下原因: 免费的网盘都有种种限制,要么不限速容量小(onedriver,google driver),要么容量大限速(百度云) 付费网 ...

  3. vue2.0项目在360兼容模式下打开空白

    安装两个依赖环境 yarn add babel-polyfill -D yarn add babel-preset-es2015 babel-cli -D 在main.js中引入babel-polyf ...

  4. HTTP缓存字段总结

    首部 通用首部:有些首部提供了与报文相关的最基本的信息,它们被称为通用首部. 请求首部:请求首部是只在请求报文中有意义的首部. 响应首部 实体首部: 用来描述HTTP报文的负荷,由于请求和响应报文中都 ...

  5. Hadoop常用命令及范例

    hadoop中的zookeeper,hdfs,以及hive,hbase都是hadoop的组件,要学会熟练掌握相关的命令及其使用规则,下面就是一些常用命令及对hbase和hive的操作语句,同时也列出了 ...

  6. mysql FORMAT() 格式化后的数字运算出错

    原文链接 FORMAT()  之后   会满三位加逗号, 在此基础上进行数字运算的时候会出现预料之外的结果, 建议使用 : convert(param, decimal(12,2)) cast(par ...

  7. 网络时间同步服务和chrony

    时间同步和chrony 时间同步:多主机协作工作时,各个主机时间同步很重要,时间不一致会造成很多重要应用的故障,如:加密协议,日志,集群等, 利用NTP(Network Time Protocol) ...

  8. Mongodb的主从复制

    主从服务器的实现原理 首先,主节点会把本服务的与写有关的操作记录下来,读操来不记录,这些操作就记录在local数据库中的oplog.$admin这个集合中,这是一个固定集合,大小是可以配置的,主要是通 ...

  9. Spring+WebSocket+SockJS实现实时聊天

    设计初衷是通过websocket实现网页实时通讯聊天. 工程环境:tomcat8+jdk1.7+maven+eclipse 设计思路:客户端登录网页建立socket连接,后台记录用户连接信息并做标识: ...

  10. SUSE 12安装详解

    1.部署步骤 1.1.启动安装程序 在启动页面上选择Installation,然后按Enter键,这将载入SUSE Linux服务器安装程序并以普通模式安装. 1.2.选择安装语言 Language和 ...