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/ ...
随机推荐
- Shell使用技巧之逐行读取
重定向读取 #!/bin/bash while read line do echo $line done < /etc/passwd 管道读取 #!/bin/bash cat /etc/pass ...
- springIOC源码接口分析(七):ApplicationEventPublisher
一 定义方法 此接口主要是封装事件发布功能的接口,定义了两个方法: /** * 通知应用所有已注册且匹配的监听器此ApplicationEvent */ default void publishEve ...
- 20190708三人开黑CF模拟赛
7月8号晚上8点和两位巨佬开了一场虚拟cf: [Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)] 我这么蔡,只A ...
- Spring Boot 2.x基础教程:默认数据源Hikari的配置详解
通过上一节的学习,我们已经学会如何应用Spring中的JdbcTemplate来完成对MySQL的数据库读写操作.接下来通过本篇文章,重点说说在访问数据库过程中的一个重要概念:数据源(Data Sou ...
- cd命令和roscd命令的区别,并解决环境变量问题
cd命令和roscd命令都是切换到指定目录的命令.不同的是,cd是Linux系统的命令,在使用时必须指定目标目录的完整路径:而roscd是ros系统中的命令,它可以直接切换到指定目录(ros系统中的软 ...
- 第四次作业:使用Packet Tracer理解RIP路由协议及ICMP协议
0 个人信息 张樱姿 201821121038 计算1812 1 实验目的 理解RIP路由表的建立与更新 感受RIP坏消息传得慢 2 实验内容 使用Packet Tracer,正确配置网络参数,使用命 ...
- Spring基础(二)_面向切面(AOP)
面向切面编程 面向切面编程[AOP,Aspect Oriented Programming]:通过预编译方式和运行期间动态代理实现程序功能的统一维护的技术.AOP 是 Spring 框架中的一个重要内 ...
- 测试用例设计:PICT的安装及使用
一.下载与安装 打开百度网页,搜索PICT,即可找到许多下载链接,点击这里,下载到桌面,点击安装.一直NEXT,安装路径保存在C盘: 二.PICT 使用 1.找到安装目录,即可看到以下内容 2.创建t ...
- Codeforces_803
A. 填k个1,使矩阵主对角线对称,相同情况选择上面1数量多的. #include<bits/stdc++.h> using namespace std; ][] = {}; int ma ...
- WeChall_Encodings: URL (Training, Encoding)
Your task is to decode the following: %59%69%70%70%65%68%21%20%59%6F%75%72%20%55%52%4C%20%69%73%20%6 ...