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/ ...
随机推荐
- python文件、文件夹的相关操作
python文件.文件夹的相关操作 #1.rename()可以完成对文件的重命名 #rename(需要修改的文件名,新的文件名) import os os.rename("readme.tx ...
- PuTTYTabManager汉化版
PuTTY Tab Manager(puttytm) V0.52 zh_CN 简体中文汉化版 功能 Putty是一款小巧好用免费的SSH客户端工具,但是不支持多标签管理,网上找了一些相关的putty多 ...
- openstack启动云主机的流程
看一下openstack启动云主机的流程图 通过上图分析可以知道: 1. 用户使用Dashboard或者CLI 把认证信息通过REST请求发送给keystone进行认证.2. Keystone校验用户 ...
- 第一篇:Vue基础
Vue基础 渐进式JavaScript框架 通过对框架的了解与运用程度,来决定其在整个项目中的应用范围,最终可以独立以框架方式完成整个web前端项目 走进Vue 什么是Vue 渐进式JavaScrip ...
- gRPC in ASP.NET Core 3.x -- Protocol Buffer(2)Go语言的例子(下)
第一篇文章(大约半年前写的):https://www.cnblogs.com/cgzl/p/11246324.html gRPC in ASP.NET Core 3.x -- Protocol Buf ...
- DOCKER 学习笔记7 Docker Machine 在阿里云实例化ECS 以及本地Windows 实例化虚拟机实战
前言 通过以上6小节的学习,已经可以使用DOCKER 熟练的部署应用程序了.大家都可以发现使用 DOCKER 带来的方便之处,因为现在的话,只是在一台服务器上部署,这样部署,我们只需要一条命令,需要的 ...
- PAT基础编程练习
7-1 厘米换算英尺英寸 (15 分) 如果已知英制长度的英尺foot和英寸inch的值,那么对应的米是(.现在,如果用户输入的是厘米数,那么对应英制长度的英尺和英寸是多少呢?别忘了1英尺等于12 ...
- MybatisDao
一.mybatisDao的编写(原始方式,不用) 1.接口编写 public interface UserDao { public void save(User user); public User ...
- Comb结合android开发
https://blog.csdn.net/qq_29665509/article/details/79272441 参考comb官方文档 https://blog.csdn.net/qq_29665 ...
- Luogu P1330 封锁阳光大学 (黑白染色)
题意: 无向图,给一个顶点染色可以让他相邻的路不能通过,但是相邻顶点不能染色,求是否可以让所有的路不通,如果可以求最小染色数. 思路: 对于无向图中的每一个连通子图,都只有两种染色方法,或者染不了,直 ...