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工 ...
随机推荐
- C#令人迷惑的DateTime:世界标准时间还是本地时间?
先来看一段代码: 复制内容到剪贴板程序代码 DateTime time = DateTime.Parse("2013-07-05 00:00:00");Console.WriteL ...
- 使用TASM编译COFF格式和连接
看到网络上流传的一份Drocon的mercury的代码程序源码使用TASM32编译使用MASM32来连接...关键的地方就在这里为什么要使用TASM编译...正常情况下TASM连接出来的程序代码体积远 ...
- VC++ 对话框下使用工具栏
关于这一技术网上也有很多的记录,下面仅记录我测试OK的代码. 在CXXDlg.h中添加如下成员变量: CToolBar m_ToolBar; CBitmap m_bmpTool; 在CXXDlg ...
- HDFS运维和优化
常见问题 下面列举HDFS运行过程中可能出现的常见问题及解决方法,这些问题一般都会在日志中出现的相应的记录.Incompatible clusterIDs in … :namenode cluster ...
- aop+自定义注解
自定义注解,并且实现,需要两个文件: 自定义注解类: package com.clc.server.annotation; import java.lang.annotation.ElementTyp ...
- ap和路由器有什么区别 ap和路由器的区别介绍【图文】
现在能够摆脱网线限制能够自由方便上网的WiFi和无线网络也来越流行,很多酒店.饭店.宾馆.办公楼等地方都会提供无线网络.而能够提供无线网络的设备有很多,现在我们介绍的是无线ap和无线路由器.那么,ap ...
- 如何反编译silverlight
@years(945060991) 15:10:28问一下 如何反编译silverlight观,一世沧桑如画♥(752816388) 15:10:46解压就行@years(945060991) ...
- SPOJ:House Fence(分治&DP)
"Holiday is coming, holiday is coming, hurray hurray!" shouts Joke in the last day of his ...
- [SoapUI] Read data from response , use it to update parameter
import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def holde ...
- poj1830开关问题——异或高斯消元
题目:http://poj.org/problem?id=1830 根据题意,构造出n元方程组: a(1,1)x1 ^ a(1,2)x2 ^ a(1,3)x3 ... a(1,n)xn = st1 ^ ...