Java 【Math】
一.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】的更多相关文章
- Java【并发】面试题
精尽 Java[并发]面试题 以下面试题,基于网络整理,和自己编辑.具体参考的文章,会在文末给出所有的链接. 如果胖友有自己的疑问,欢迎在星球提问,我们一起整理吊吊的 Java[并发]面试题的大保健. ...
- Java SE API —— 【Math 】之【BigInteger】类
目录 概述 构造方法 BigInteger(byte[] val) 概述 不可变的任意精度的整数.提供了模算术.GCD 计算.质数测试.素数生成.位操作以及一些其他操作. 算术运算的语义完全模仿 Ja ...
- tfserving 调用deepfm 并预测 java 【参考】
https://blog.csdn.net/luoyexuge/article/details/79941565?utm_source=blogxgwz8 首先是libsvm格式数据生成java代码, ...
- 从头开始学Java【1】
1:常见的DOS命令 盘符的切换 d:回车 目录的进入 cd javase cd javase\day01\code 目录的回退 cd.. cd\ 清屏 cls 退出 exit 创建目录 md 删除目 ...
- java【基础】正则表达式
1 字符串判断 java的正则使用的是Pattern以及Matcher来配合使用的. 如果只是用来判断输入的字符串是否符合格式,推荐使用Matcher的matches方法. public static ...
- XmlRpc with C#/Java【转】
最近看了几个项目都是用xmlrpc协作完成的,就做了几个测试客户端和服务器端和大家一起分享.希望能对入门的同学有帮助 关于xmlrpc的介绍和规范参考http://www.xml-rpc.net/ 下 ...
- 栈的图文解析 和 对应3种语言的实现(C/C++/Java)【转】
概要 本章会先对栈的原理进行介绍,然后分别通过C/C++/Java三种语言来演示栈的实现示例.注意:本文所说的栈是数据结构中的栈,而不是内存模型中栈.内容包括:1. 栈的介绍2. 栈的C实现3. 栈的 ...
- JAVA【一】
1,abstract可以修饰什么?为什么不能修饰属性 --abstract是抽象的意思,在java中,规定只能修饰类或者方法,所以不能修饰属性. (1)abstract修饰类,会使这个类成为一个抽象类 ...
- Java【tomcat】配置文件
Tomcat(二):tomcat配置文件server.xml详解和部署简介 分类: 网站架构 本文原创地址在博客园:https://www.cnblogs.com/f-ck-need-u/p/ ...
随机推荐
- 报错requests.exceptions.InvalidSchema: No connection adapters were found for
刚开始学习,使用requests时,敲了点demo import requests params = { "name": "name", "passw ...
- CUDA学习(三)之使用GPU进行两个数组相加
传入两个数组,在GPU中将两个数组对应索引位置相加 #include "cuda_runtime.h" #include "device_launch_parameter ...
- 【WPF学习】第三十五章 资源字典
如果希望在多个项目之间共享资源,可创建资源字典.资源字典只是XAML文档,除了存储希望使用的资源外,不做其他任何事情. 一.创建资源字典 下面是一个资源字典示例,它包含一个资源: <Resour ...
- 实验12: OSPF
实验9-1:单区域点到点链路的OSPF 实验目的通过本实验可以掌握:(1)在路由器上启动OSPF 路由进程(2)启用参与路由协议的接口,并且通告网络及所在的区域(3)度量值cost 的计算(4)点到点 ...
- HDU 1251 统计难题 (Trie树模板题)
题目链接:点击打开链接 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单 ...
- How to collect TLOG usage status automatically ?
Yes , in SQLSERVER, we use "DBCC sqlperf(logspace)" to check transaction logfile status.Bu ...
- Mongodb 3.2.8: 集群环境搭建
简介 MongoDB是一种面向文档的数据库管理系统,由C++撰写而成,以此来解决应用程序开发社区中的大量现实问题.2007年10月,MongoDB由10gen团队所发展.2009年2月首度推出. ## ...
- Gorm与数据库(单复数)表结构之间的映射
Gorm连接MySQL: import ( _ "github.com/go-sql-driver/mysql" "github.com/jinzhu/gorm" ...
- CentOS使用465端口发送邮件
1)邮件发送示例 方法1:echo "This is a test mail" | mail -s '邮件测试' 452666750@qq.com 方法2:mail -s '服务运 ...
- [Effective Java 读书笔记] 第二章 创建和销毁对象 第二条
第二条 遇到多个构造器参数时,可以考虑用构建器 当遇到有多个构造器参数时,常见的是用重叠构造器,即: public class TestClass{ public TestClass(int para ...