Math类概述

在java.lang包下,有个Math类,这个类包含用于执行基本数学运算的方法,如四舍五入,开方等等。

package com.sutaoyu.usually_class;

public class String_test10 {
public static void main(String[] args) {
//圆周率
System.out.println(Math.PI); //3.141592653589793 //取绝对值
System.out.println(Math.abs(-10)); //10 //ceil天花板,会向上取值,结果是double
System.out.println(Math.ceil(12.11));//13.0
System.out.println(Math.ceil(9.89));//10.0 //floor地板,会向下取整,结果是double
System.out.println(Math.floor(11.11));//11.0
System.out.println(Math.floor(7.89));//7.0 //获取两个值中的最大值
System.out.println(Math.max(100, 80));//100 //前面的数是底数,后面的数是指数,即2的3次方
System.out.println(Math.pow(2, 3));//8.00 //生成0.0到1.0之间的随机小数,包括0.0,不包括1.0
System.out.println(Math.random()); //0.7952284902360376 //四舍五入
System.out.println(Math.round(12.3f));//
System.out.println(Math.round(9.8f));//10 //开平方
System.out.println(Math.sqrt(27));//5.196152422706632 }
}

13、Math类简介的更多相关文章

  1. C# Math类简介运用

    总结了一下几个常用的Math类 /* ######### ############ ############# ## ########### ### ###### ##### ### ####### ...

  2. C# Math类简介

    Math.abs() 计算绝对值. Math.acos() 计算反余弦值. Math.asin() 计算反正弦值. Math.atan() 计算反正切值. Math.atan2() 计算从x 坐标轴到 ...

  3. Math类简介

    Math  abs max min 分别是绝对值 最大值,最小值 round 四舍五入 ceil ceil(32.6)  33.0 ceil(32.2) 33.0 返回大于该数值的较大的整数 与之相对 ...

  4. 01 语言基础+高级:1-3 常用API第一部分_day08【String类、static、Arrays类、Math类】

    day08[String类.static.Arrays类.Math类] String类static关键字Arrays类Math类 教学目标能够使用String类的构造方法创建字符串对象能够明确Stri ...

  5. Math类

    Math类:用于执行基本数学运算的方法 方法: public static int abs(int a):绝对值 public static double ceil(double a):向上取整   ...

  6. string、math类、random随机数、datetime、异常保护

    今天讲的知识点比较多,比较杂,以至于现在脑子里还有点乱,慢慢来吧... string (1)string.length; (获得你string字符串的长度) (2)a = a.Trim(); 重新赋值 ...

  7. 关于Math类的round、floor、ceil三个方法

    一.Math类这三个方法的简介 1.round():取最接近的值. 对于这个方法,查看源代码,其实现如下: public static long round(double a) { if (a != ...

  8. Java学习笔记26(Math类、Arrays类、BigInteger类、BigDecimal类)

    Math类:数学工具类,做一些数学计算,开方,对数,三角函数等 所有方法都是静态方法,不需要建立对象,直接用类名调用即可 示例: 这里写几个在日常开发中会用到的,比如三角函数之类的平时不会用到,了解即 ...

  9. java 基本类型包装类,system类,Math类,Assrays类,大数据运算

    实现字符串与基本数据之间转换 将字符串转成基本数据类型方法 例如:将字符串转成成int类型 String str ="123"; int a =Integer.parseInt(s ...

随机推荐

  1. [转帖] IIS 与 HTTP/2 的介绍.

    HTTP/2 on IIS https://blogs.iis.net/davidso/http2 Friday, September 11, 2015 Windows 10 HTTP2 In Oct ...

  2. [转帖]Cgroups 与 Systemd

    Cgroups 与 Systemd 大神的文章很牛B .. https://www.cnblogs.com/sparkdev/p/9523194.html 看不太懂 , 转帖一下 自己留着好好看呢. ...

  3. Matplotlib风羽自定义

    [前言]对于气象专业的小学生来说,风场是预报重要的参考数据,我们所知的风羽有四种:短线代表风速2m/s,长线代表风速4m/s,空心三角代表风速20m/s,实心三角代表风速50m/s.而matplotl ...

  4. MT【141】逆用特征根法

    (清华大学THUSSAT) 已知 \(a=\left( \dfrac{-1+\sqrt{5}}{2} \right)^{-10}+\left( \dfrac{-1-\sqrt{5}}{2} \righ ...

  5. 内容显示在HTML页面底端的一些处理方式

    1.概要: 手机页面底端有时候需要显示版权信息,诸如一行文字或者一个背景图片,但是页面的滚动长度未知,需要考虑两个问题 当页面高度小于屏幕高度时候: 希望最后一行信息显示在屏幕底端,同时也就是页面底端 ...

  6. Storm入门到精通(四)---本地实例Demo

    单词实时计数 maven项目的结构: 一.Pom.xml [html] view plain copy <project xmlns="http://maven.apache.org/ ...

  7. BZOJ 4520: [Cqoi2016]K远点对

    4520: [Cqoi2016]K远点对 Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 638  Solved: 340[Submit][Status ...

  8. USACO Section 1.5 Superprime Rib 解题报告

    题目 题目描述 超级素数的定义如下:如果有个素数我们从右往左依次去掉一位数,每次去掉一位数剩下的数仍然是素数,那么我们称这个数是超级素数.例如7331,这是一个素数,从右往左依次去掉一位数733, 7 ...

  9. Nginx web服务优化 (一)

    1.Nginx基本安全优化 a.更改配置文件参数隐藏版本 编辑nginx.conf配置文件增加参数,实现隐藏Nginx版本号的方式如下.在nginx配置文件nginx.conf中的http标签段内加入 ...

  10. python之旅:并发编程之多线程

    一 threading模块介绍 multiprocess模块的完全模仿了threading模块的接口,二者在使用层面,有很大的相似性,因而不再详细介绍 官网链接:https://docs.python ...