java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))
- public class MathDemo {
- public static void main(String args[]){
- /**
- * 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
- /**
- * 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
- /**
- * max 两个中返回大的值,min和它相反,就不举例了
- */
- System.out.println(Math.max(-10.1, -10)); //-10.0
- System.out.println(Math.max(10.7, 10)); //10.7
- System.out.println(Math.max(0.0, -0.0)); //0.0
- /**
- * random 取得一个大于或者等于0.0小于不等于1.0的随机数
- */
- System.out.println(Math.random()); //0.08417657924317234
- System.out.println(Math.random()); //0.43527904004403717
- /**
- * 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
- }
- }
- public class MathDemo {
- public static void main(String args[]){
- /**
- * 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
- /**
- * 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
- /**
- * max 两个中返回大的值,min和它相反,就不举例了
- */
- System.out.println(Math.max(-10.1, -10)); //-10.0
- System.out.println(Math.max(10.7, 10)); //10.7
- System.out.println(Math.max(0.0, -0.0)); //0.0
- /**
- * random 取得一个大于或者等于0.0小于不等于1.0的随机数
- */
- System.out.println(Math.random()); //0.08417657924317234
- System.out.println(Math.random()); //0.43527904004403717
- /**
- * 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方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))的更多相关文章
- java中常用的字符串的截取方法
java中常用的字符串的截取方法 1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int l ...
- java中常用的包、类、以及包中常用的类、方法、属性----sql和text\swing
java中常用的包.类.以及包中常用的类.方法.属性 常用的包 java.io.*; java.util.*; java.lang.*; java.sql.*; java.text.*; java.a ...
- 【Java】Java中常用的String方法
本文转载于:java中常用的String方法 1 length()字符串的长度 String a = "Hello Word!"; System.out.println(a.len ...
- Java高级特性 第2节 java中常用的实用类(1)
一.Java API Java API即Java应用程序编程接口,他是运行库的集合,预先定义了一些接口和类,程序员可以直接调用:此外也特指API的说明文档,也称帮助文档. Java中常用的包: jav ...
- Java 中的浮点数取精度方法
Java 中的浮点数取精度方法 一.内容 一般在Java代码中取一个double类型的浮点数的精度,四舍五入或者直接舍去等的方式,使用了4种方法,推荐使用第一种,我已经封装成工具类了. 二.代码实现 ...
- java 中常用的类
java 中常用的类 Math Math 类,包含用于执行基本数学运算的方法 常用API 取整 l static double abs(double a) 获取double 的绝对值 l sta ...
- java中常用的工具类(二)
下面继续分享java中常用的一些工具类,希望给大家带来帮助! 1.FtpUtil Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- Java中常用的查找算法——顺序查找和二分查找
Java中常用的查找算法——顺序查找和二分查找 神话丿小王子的博客 一.顺序查找: a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数据最后一位 ...
- java中常用的工具类(三)
继续分享java中常用的一些工具类.前两篇的文章中有人评论使用Apache 的lang包和IO包,或者Google的Guava库.后续的我会加上的!谢谢支持IT江湖 一.连接数据库的综合类 ...
- java中常用的工具类(一)
我们java程序员在开发项目的是常常会用到一些工具类.今天我汇总了一下java中常用的工具方法.大家可以在项目中使用.可以收藏!加入IT江湖官方群:383126909 我们一起成长 一.String工 ...
随机推荐
- Xcode6.1 Prefix.pch添加方式
本文转载:http://blog.csdn.net/foolsong/article/details/40653497 在Xcode6.1中创建工程默认是没有Prefix.pch文件的,需要 ...
- Java实现HttpClient发送GET、POST请求(https、http)
1.引入相关依赖包 jar包下载:httpcore4.5.5.jar fastjson-1.2.47.jar maven: <dependency> <groupId>o ...
- js获取三天后的日期
js获取三天后的日期 setDate getNowAddTreeFormatDate() { var date = new Date(); date.setDate(date.getDate()+3) ...
- 百度自然语言处理api用法
def words url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=1111111" param ...
- HDU3667 Transportation —— 最小费用流(费用与流量平方成正比)
题目链接:https://vjudge.net/problem/HDU-3667 Transportation Time Limit: 2000/1000 MS (Java/Others) Me ...
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
在做一个view背景特效的时候被坐标的各个获取方法搞晕了,几篇抄来抄去的博客也没弄很清楚. 现在把整个总结一下. 其实只要把下面这张图看明白就没问题了. 涉及到的方法一共有下面几个: view获取自身 ...
- JRE System Library 与Java EE Libraries的区别
JRE System Library是只要做java开发都需要的完整的.标准的库. Java EE5 Libraries只是java三个方向中做java EE所需要的库.如果做Web方面的开发的话就 ...
- skynet源码阅读<6>--线程调度
相比于上节我们提到的协程调度,skynet的线程调度从逻辑流程上来看要简单很多.下面我们就来具体做一分析.首先自然是以skynet_start.c为入口: static void start(int ...
- Opencv实现简易播放器
实现了在MFC中显示图片,再要显示一个视频就是轻而易举的事了,本篇介绍使用Opencv制作一个简易的播放器,实现打开文件.暂停.继续播放.再次播放和总\当前帧数显示功能. 首先还是先看一下界面效果: ...
- BZOJ_5311_贞鱼_决策单调性+带权二分
BZOJ_5311_贞鱼_决策单调性+带权二分 Description 众所周知,贞鱼是一种高智商水生动物.不过他们到了陆地上智商会减半. 这不?他们遇到了大麻烦! n只贞鱼到陆地上乘车,现在有k辆汽 ...