一.Math类的使用方法

public class demo{
public static void main(String[] args){
double pi = Math.PI; //Math函数库
System.out.println(pi);
}
}

二.Number & Math方法

1.xxxValue方法  (将 Number 对象转换为xxx数据类型的值并返回。)

public class demo{
public static void main(String[] args){
Integer x = ;
System.out.println(x.byteValue()); //int 转换为xxx
System.out.println(x.doubleValue());
System.out.println(x.floatValue());
System.out.println(x.intValue());
System.out.println(x.longValue());
System.out.println(x.shortValue()); }
}

2.compareTo方法(将number对象与参数比较。)

public class demo{
public static void main(String[] args){
Integer x = ;
System.out.println(x.compareTo());
System.out.println(x.compareTo());
System.out.println(x.compareTo()); }
}

3.equals(判断number对象是否与参数相等。)

public class demo{
public static void main(String[] args){
Integer x = ; //整型
Integer y = ;//整型
Integer z =;//整型
Short a = ; //短整型 System.out.println(x.equals(y));
System.out.println(x.equals(z));
System.out.println(x.equals(a)); }
}

4.valueOf(返回一个 Number 对象指定的内置数据类型)

public class demo{
public static void main(String[] args){
//将数值9转换为整型
Integer x = Integer.valueOf();
//将数据5转换成双精度
Double c = Double.valueOf();、
//将字符串5转换为双精度
Double d = Double.valueOf("");
//将字符串80转换为浮点型
float a = Float.valueOf("");
//"444"(16进制) --> 10进制数
Integer b = Integer.valueOf("",); System.out.println(x);
System.out.println(c);
System.out.println(a);
System.out.println(b);
System.out.println(d); }
}

5.toString(以字符串形式返回值。)

public class demo{
public static void main(String[] args){
Integer x = ; //x转换为字符串类型
System.out.println(x.toString());
//将12整型转换为字符串
System.out.println(Integer.toString()); }
}

6.parseInt(将字符串解析为int类型。)

public class demo{
public static void main(String[] args){
//将字符型9转换为整型
int x = Integer.parseInt("");
//将字符串5转换为双精度5
double c = Double.parseInt("");
//将16进制的字符数转化为整型(10进制)
int b = Integer.parseInt("",); System.out.println(x);
System.out.println(c);
System.out.println(b); }
}

7.abs(返回参数的绝对值。)

public class demo{
public static void main(String[] args){ Integer a = -;
double d = -;
float f = -;
//返回对应的绝对值
System.out.println(Math.abs(a));
System.out.println(Math.abs(d));
System.out.println(Math.abs(f)); }
}

8.ceil(返回大于等于( >= )给定参数的的最小整数,类型为双精度浮点型。)

9.floor(返回小于等于(<=)给定参数的最大整数 。)

public class demo{
public static void main(String[] args){ double d = 100.675;
float f = -;
//向上取整
System.out.println(Math.ceil(d));
System.out.println(Math.ceil(f));
//向下取整
System.out.println(Math.floor(d));
System.out.println(Math.floor(f)); }
}

10.rint(返回与参数最接近的整数。返回类型为double。)

功能:返回参数最接近的值,如果两边都接近,取偶数值
public class demo{
public static void main(String[] args){ double d = 100.675;
double e = 100.500;
double f = 100.200;
//取接近值
System.out.println(Math.rint(d));
System.out.println(Math.rint(e));
System.out.print(Math.rint(f)); }
}

11.round(它表示四舍五入)

public class demo{
public static void main(String[] args){ double d = 100.675; //
double e = 100.500; //
float f = ; //
float g = 90f; // System.out.println(Math.round(d));
System.out.println(Math.round(e));
System.out.println(Math.round(f));
System.out.println(Math.round(g)); }
}

12.min(返回两个参数中的最小值。)

13.max(返回两个参数中的最大值。)

public class demo{
public static void main(String[] args){ int a = ;
int b = ; System.out.println("a,b中的最大值:" + Math.max(a,b));
System.out.println("a,b中的最小值" + Math.min(a,b)); }
}

14.exp(返回自然数底数e的参数次方。)

public class demo{
public static void main(String[] args){ double x = 45.0;
double y = 30.0; //输出数学E的值
System.out.printf("e的值为%.4f%n",Math.E);
//输出e的x次幂的值
System.out.printf("exp(%.3f)为%.3f%n",x,Math.exp(x)); }
}

15.log(返回参数的自然数底数的对数值。)

public class demo{
public static void main(String[] args){ double x = Math.E; //log以e为底e的值
System.out.printf("exp(%.3f)为%.3f%n",x,Math.log(x)); }
}

16.pow(返回第一个参数的第二个参数次方。)

public class demo{
public static void main(String[] args){ double x = ;
double y = ; //x的y次幂
System.out.printf("exp(%.3f,%.3f)为%.3f%n",x,y,Math.pow(x,y)); }
}

17.sqrt(求参数的算术平方根。)

public class demo{
public static void main(String[] args){ double x = ; //x的开根号
System.out.printf("sqrt(%.3f)为%.3f%n",x,Math.sqrt(x)); }
}

18.sin(求指定double类型参数的正弦值。)

public class demo{
public static void main(String[] args){ double degrees = 45.0; //角度
double radians = Math.toRadians(degrees); //转化为弧度 System.out.format("pi 的值为 %.4f%n", Math.PI);
System.out.format("%.1f 度的正弦值为 %.4f%n", degrees, Math.sin(radians)); }
}

19.cos(求指定double类型参数的余弦值。)

20.tan(求指定double类型参数的正切值。)

21.asin(求指定double类型参数的反正弦值。)

22.acos(求指定double类型参数的反余弦值。)

23.atan(求指定double类型参数的反正切值。)

24.atan2(将笛卡尔坐标转换为极坐标,并返回极坐标的角度值。)

25.toDegrees(将参数转化为角度。)

26.toRadians(将角度转换为弧度。)

27.random(返回一个随机数。)

Java 【Math】的更多相关文章

  1. Java【并发】面试题

    精尽 Java[并发]面试题 以下面试题,基于网络整理,和自己编辑.具体参考的文章,会在文末给出所有的链接. 如果胖友有自己的疑问,欢迎在星球提问,我们一起整理吊吊的 Java[并发]面试题的大保健. ...

  2. Java SE API —— 【Math 】之【BigInteger】类

    目录 概述 构造方法 BigInteger(byte[] val) 概述 不可变的任意精度的整数.提供了模算术.GCD 计算.质数测试.素数生成.位操作以及一些其他操作. 算术运算的语义完全模仿 Ja ...

  3. tfserving 调用deepfm 并预测 java 【参考】

    https://blog.csdn.net/luoyexuge/article/details/79941565?utm_source=blogxgwz8 首先是libsvm格式数据生成java代码, ...

  4. 从头开始学Java【1】

    1:常见的DOS命令 盘符的切换 d:回车 目录的进入 cd javase cd javase\day01\code 目录的回退 cd.. cd\ 清屏 cls 退出 exit 创建目录 md 删除目 ...

  5. java【基础】正则表达式

    1 字符串判断 java的正则使用的是Pattern以及Matcher来配合使用的. 如果只是用来判断输入的字符串是否符合格式,推荐使用Matcher的matches方法. public static ...

  6. XmlRpc with C#/Java【转】

    最近看了几个项目都是用xmlrpc协作完成的,就做了几个测试客户端和服务器端和大家一起分享.希望能对入门的同学有帮助 关于xmlrpc的介绍和规范参考http://www.xml-rpc.net/ 下 ...

  7. 栈的图文解析 和 对应3种语言的实现(C/C++/Java)【转】

    概要 本章会先对栈的原理进行介绍,然后分别通过C/C++/Java三种语言来演示栈的实现示例.注意:本文所说的栈是数据结构中的栈,而不是内存模型中栈.内容包括:1. 栈的介绍2. 栈的C实现3. 栈的 ...

  8. JAVA【一】

    1,abstract可以修饰什么?为什么不能修饰属性 --abstract是抽象的意思,在java中,规定只能修饰类或者方法,所以不能修饰属性. (1)abstract修饰类,会使这个类成为一个抽象类 ...

  9. Java【tomcat】配置文件

    Tomcat(二):tomcat配置文件server.xml详解和部署简介   分类: 网站架构   本文原创地址在博客园:https://www.cnblogs.com/f-ck-need-u/p/ ...

随机推荐

  1. UNIX 版本

    一般UNIX系统都来源于AT&T公司的System V UNIX系统,BSD UNIX或其他类UNIX系统. System V UNIX:当今市场上大多数主要的商业UNIX系统都是基于AT&a ...

  2. react中 如何使用图片

    //render 第一种方法:先const一个对象,把需要应用图片的dom上的style写入对象中, 然后在return()中使用style关键字赋值为预先定义的那个style对象 const bgG ...

  3. math type白嫖教程

    math type作为一款很方便的公式编辑器,缺陷就是要收费,只有30天的免费试用.这里有一个白嫖的方法,当你30天的期限过了之后,只需要删除HKEY_CURRENT_USER\Software\In ...

  4. asp.net core 3.x 身份验证-1涉及到的概念

    前言 从本篇开始将围绕asp.net core身份验证写个小系列,希望你看完本系列后,脑子里对asp.net core的身份验证原理有个大致印象.至于身份验证是啥?与授权有啥联系?就不介绍了,太啰嗦. ...

  5. 介绍Netty

    介绍Netty 概述 Netty是由JBOSS提供的一个java开源框架,现为 Github上的独立项目.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高可靠性的网络服务 ...

  6. ATL的GUI程序设计(1)

    from:http://blog.titilima.com/atlgui-1.html 第一章 不能免俗的"Hello, World!" 在这一章里,就像所有的入门级教程一样,我也 ...

  7. Codeforces 1087C Connect Three (思维+模拟)

    题意: 网格图选中三个格,让你选中一些格子把这三个格子连起来,使得选中的格子总数最小.最后输出方案 网格范围为1000 思路: 首先两点间连起来最少需要的格子为他们的曼哈顿距离 然后连接方案一定是曼哈 ...

  8. 第2章 Java并行程序基础(二)

    2.3 volatile 与 Java 内存模型(JMM) volatile对于保证操作的原子性是由非常大的帮助的(可见性).但是需要注意的是,volatile并不能代替锁,它也无法保证一些复合操作的 ...

  9. 使用docker19.03.6部署zabbix

    可参考官方文档:https://www.zabbix.com/documentation/4.0/zh/manual/installation/containers 1)启动一个空的mysql服务器实 ...

  10. mongo操作备忘

    #查看collection内 某个字段条目数 db.dictionary_system.find({"name":"xxx"}).count() #清空某个co ...