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工 ...
随机推荐
- Windows 8实用窍门系列:20.Windows 8中的GridView使用(二)和DataTemplateSelector
在本文中所讲述内容的实例仍然沿用于上篇文章,有什么疑惑可以参考上篇文章. 一 GroupStyle 在GridView控件中我们可以对数据进行分组显示,通过对GridView的GroupStyle进行 ...
- cocoapods导入框架出错 The dependency `FMDB` is not used in any concrete target
问题描述: The dependency `FMDB` is not used in any concrete target 解决办法: 官网是这样给推荐的: 在创建Podfile的时候,用这种格式使 ...
- python day- 7 进本数据类型的先关知识点 set集合 深浅拷贝
一.基本数据类型相关知识 1.str. join()函数 关于字符串 a = "我爱北京" b = a.join("真的") 将&q ...
- hihocoder #1039 : 字符消除 ( 字符串处理类 ) 好久之前做的题目,具体的算法代码中阅读吧
#1039 : 字符消除 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消 ...
- 织梦栏目页分页title加"第N页"
以上就是调用栏目管理的SEO标题代码:{dede:field.seotitle /}的方法,这样充分体现列表页标题显示的效果,有利于搜索引擎的收录. 第二个问题就是这样列表页的标题都成了一个样子的了, ...
- java 开发面试题小整理(二)
51.Anonymous Inner Class(匿名内部类)是否可以继承其它类?是否可以实现接口? 答:可以继承其他类或实现其他接口,在Swing编程和Android开发中常用此方式来实现事件监听和 ...
- ubuntu IP 扫描
/******************************************************************************* * ubuntu IP 扫描 * 说明 ...
- [USACO2012 OPEN] Bookshelf
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2678 [算法] 首先不难想到如下DP : 记f[i]表示前i本书的高度和最小值 显然 ...
- GYM 100741A Queries
传送门 题目大意: 一个长度为n的序列,q次三种操作 +p r:下标为p的数+r -p r:下标为p的数-r s l r mod [L,R]中有多少数%m=mod,m已经给出 题解: 开十个树状数组 ...
- javascript之this指向
情况一: 如果一个函数中有this,但是没有被上一级调用,this指向window 例: function a(){ var num='11'; console.log(this.num); //u ...