Math 类的使用(一小部分)

 1 package com.Date.Math;
 2 /*
 3 Math 数学类, 主要是提供了很多的数学公式。
 4
 5 abs(double a)  获取绝对值
 6 ceil(double a)  向上取整
 7 floor(double a)  向下取整
 8 round(float a)   四舍五入
 9 random()   产生一个随机数. 大于等于 0.0 且小于 1.0 的伪随机 double 值
10
11 */
12 public class Mathuse {
13
14     public static void main(String[] args) {
15
16         System.out.println("获取绝对值,"+Math.abs(3.14));
17
18         System.out.println("向上取整,"+Math.ceil(-3.14));
19
20         System.out.println("向下取整,"+Math.floor(3.14));
21
22         System.out.println("四舍五入,"+Math.round(3.56));
23
24         System.out.println("产生随机数,"+Math.random());
25
26     }
27
28 }

时间: 2024-08-07 13:59:30

Math 类的使用(一小部分)的相关文章

Math类

java提供了基本的+,-,*,/算数运算符,同时也提供了更复杂的运算符,比如三角函数,对数元,指数运算 Math是一个工具类.它的构造器被定义为private,因此无法创建Math类的对象,Math类中的所有方法都是 类方法,可以直接通过类名来调用,Math除了提供了大量的静态方法,还提供了两个类变量PI和E public class MathTest{ public static void main(String[] args){ //将弧度转化成角度 System.out.println(

Math类概述及其成员方法

Math 类包括用于运行基本数学运算的方法,如初等指数.对数.平方根和三角函数,这个类寻常开发中用的不多,可是在某些需求上会用到,比方求二个用户年龄的相差多少岁,这会用到Math类中的方法!如今把Maht几个经常使用的方法列举一下, public static int abs(int a) 求一个数的绝对值 public static double ceil(double a) 向上取大于这个数的最小整数 public static double floor(double a) 向下取这个值最大

Java Math类

1 package demo04; 2 3 //Math类所有方法都是静态方法,直接类名调用 4 public class MathDemo { 5 public static void main(String[] args) { 6 7 //static int abs(int a) 返回 int 值的绝对值 8 System.out.println(Math.abs(-1)); //1 9 10 //static double ceil(double a) 向上取整 11 System.ou

Math类的round方法小解

在Math类中有三个关于“四舍五入”的静态方法(ceil,floor,round): ① Math.ceil(number) 向上取整,Math.ceil(11.2) 结果:12              Math.ceil(11.6) 结果:12 Math.ceil(-11.2) 结果:-11            Math.ceil(-11.6) 结果:-11 ② Math.floor(number) 向下取整, Math.floor(11.2) 结果11              Math

Math类++Date类

package day06; /***** * Math类的演示 * Math类: * 1,Math类是final的 * 2,Math的构造方法是private的(不能手工new) * 3,Math提供的方法是静态的(全部都可以调用) * 常用的方法: * abs:绝对值 * sqrt:平方根 * pow(double a ,double b) a的b次幂 * log    自然对数 * exp    e为底的指数 * max(double a ,double b)    两个数求最大值 * m

JAVA API(三) Math类和Random类

1.Math类 Math类是数学操作类,提供了一些用于进行数学计算的静态方法.Math类中有两个静态常量PI和E,分别代表数学常量π和e. 列表中是Math类的一些常用方法: 方法声明 功能描述 int abs(int a) 计算a的绝对值 double ceil(double a) 向上取整,求大于参数的最小整数 double  floor(double a ) 向下取整,求小于参数的最大整数 long round(double a) 表示四舍五入,算法为Math.floor(a+0.5) d

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

今天讲的知识点比较多,比较杂,以至于现在脑子里还有点乱,慢慢来吧... string (1)string.length; (获得你string字符串的长度) (2)a = a.Trim(); 重新赋值 (3)string.Trim(); 去掉字符串前后空格 (4)string.TrimStart(); 去掉前面的空格 (5)string.TrimEnd(); 去掉后面的空格 (6) string.ToLower(); 将所有大写字母转换为小写 (7)string.ToUpper(); 将所有小写

string类;math类;datetime类

String类: .Length 字符的长度 .Trim() 去掉开头以及结尾的空格 .TrimStart() 去掉字符串开头的空格 .TrimEnd() 去掉字符串后面的空格 .ToUpper() 全部大写 .ToLower() 全部小写 Substring(起始位置,截取长度) Substring(起始位置) 只写起始位置,可以截取到尾 身份证截取生日 IndexOf("字符串") 返回第一次出现此字符串的索引 LastIndexOf("字符串") 返回最后一次

Math类,System.Math

public static double Round( double value,//要舍入的双精度浮点数. int digits//返回值中的小数数字.)将双精度浮点值按指定的小数位数舍入. 说明:digits is zero, an integer is returned.' data-guid="5045d582a1128e55c6e57e080dc6901f">由于用十进制数表示浮点数或对浮点数进行算术运算可能导致的误差,在某些情况下,Round(Double, Int3

Java Math类(java.lang包)

Math类包含用于执行基本数学运算的方法,其所有方法都是静态方法,所以使用该类中的方法时,可以直接使用类名.方法名,如: Math.round();