Java学习笔记-Math类
并非所有的类都需要main方法.Math类和JOptionPane类都没有main方法.这些类中所包含的方法主要是为了供其他类使用.
package welcome;
public class TestMath {
public static void main(String[] args) {
// 三角函数方法
System.out.println(Math.toDegrees(Math.PI / 2));
System.out.println(Math.toRadians(30));
System.out.println(Math.sin(0));
System.out.println(Math.toRadians(270));
System.out.println(Math.sin(Math.PI / 6));
System.out.println(Math.sin(Math.PI / 2));
System.out.println(Math.sin(Math.PI / 3));
System.out.println(Math.cos(0));
System.out.println(Math.cos(Math.PI / 6));
System.out.println(Math.cos(Math.PI / 2));
System.out.println(Math.asin(0.5));
System.out.println("-----------------------");
// 指数函数方法
System.out.println(Math.exp(1));
System.out.println(Math.log(Math.E));
System.out.println(Math.log10(10));
System.out.println(Math.pow(2, 3));
System.out.println(Math.pow(3, 2));
System.out.println(Math.pow(3.5, 2.5));
System.out.println(Math.sqrt(4));
System.out.println(Math.sqrt(10.5));
System.out.println("-------------------------");
// 取整方法
System.out.println(Math.ceil(2.1));
System.out.println(Math.ceil(2.0));
System.out.println(Math.ceil(-2.0));
System.out.println(Math.ceil(-2.1));
System.out.println(Math.floor(2.1));
System.out.println(Math.floor(2.0));
System.out.println(Math.floor(-2.0));
System.out.println(Math.floor(-2.1));
System.out.println(Math.rint(2.1));
System.out.println(Math.rint(-2.0));
System.out.println(Math.rint(-2.1));
System.out.println(Math.rint(2.5));
System.out.println(Math.rint(3.5));
System.out.println(Math.rint(-2.5));
System.out.println();
System.out.println(Math.round(2.6F));
System.out.println(Math.round(2.0));
System.out.println(Math.round(-2.6));
System.out.println(Math.round(-2.0F));
// min, max 和 abs方法
System.out.println("min, max 和 abs方法");
System.out.println(Math.min(2, 3));
System.out.println(Math.max(2.5, 3));
System.out.println(Math.max(2.5, 3.6));
System.out.println(Math.abs(-2));
System.out.println(Math.abs(-2.1));
// random方法
System.out.println((int)(Math.random() * 100)); // 返回0到99之间的一个随机整数
System.out.println(50 + (int)(Math.random() * 50)); // 返回50到99之间的一个随机整数
// a + Math.random() * b 返回a到a+b之间但不包括a+b的一个随机数
}
}
Java学习笔记-Math类的更多相关文章
- Java学习笔记——File类之文件管理和读写操作、下载图片
Java学习笔记——File类之文件管理和读写操作.下载图片 File类的总结: 1.文件和文件夹的创建 2.文件的读取 3.文件的写入 4.文件的复制(字符流.字节流.处理流) 5.以图片地址下载图 ...
- Java学习笔记之---类和对象
Java学习笔记之---类和对象 (一)类 类是一个模板,它描述一类对象的行为和状态 例如:动物类是一个类,动物们都有属性:颜色,动物们都有行为:吃饭 public class Dog { Stri ...
- 3.4常用类(java学习笔记)Math和Random
一.Math 这个类包含执行指数.对数.平方根法.三角函数等基本的数字运算. Math中还包含一些静态常量供我们调用. 如PI圆周率,E. 1.abs(),返回该数的绝对值. public class ...
- 0018 Java学习笔记-面向对象-类的基本要素
类与对象 大街上一个个的人,就是一个个对象 类是对一群对象的抽象,比如人都有性别.年龄.姓名,都会吃饭.睡觉等.姓名性别可以抽象为变量,吃饭睡觉可以抽象为方法,像下面一样定义个类来形容人 public ...
- Java学习--使用 Math 类操作数据
使用 Math 类操作数据 Math 类位于 java.lang 包中,包含用于执行基本数学运算的方法, Math 类的所有方法都是静态方法,所以使用该类中的方法时,可以直接使用类名.方法名,如: M ...
- java学习笔记--常用类
一.Math类:针对数学运算进行操作的类 1.常用的方法 A:绝对值 public static int abs(int a) B:向上取整 public static double ceil( ...
- Java学习之Math类理解
Math类包含用于几何和三角运算的所有浮点函数,以及一些用于通用目的的方法.Math类定义了两个double常量:E(约等于2.72)和PI(约等于3.14) 1.三角函数 表中的方法接收double ...
- Java学习笔记-File类的基本方法
要渐渐养成写博客的习惯-----> 前段时间看Mars的java中的I/O流没怎么懂,发现I/O流好难啊.今天重新看一遍其他教学,还有书籍,做些笔记,记录下每天的学习生活. File类的一些方法 ...
- Java学习笔记 04 类和对象
一.类和对象的概念 类 >>具有相同属性和行为的一类实体 对象 >>实物存在的实体.通常会将对象划分为两个部分,即静态部分和动态部分.静态部分指的是不能动的部分,被称为属性,任 ...
随机推荐
- jqgrid+bootstrap样式实践
jqgrid+bootstrap样式实践,报错数据加载,选中,删除等功能 需要引入的样式 bootstrap.min.css ui.jqgrid.css 需要引入的JS jquery.min.js b ...
- oncopy="document.selection.empty()"跟oncopy="return false"什么区别?
实现效果一样,禁止复制. 区别: oncopy="document.selection.empty()" 没禁止,只是把它复制的内容,变成空了: oncopy="ret ...
- 【MSSQL】MSSQL还原单mdf文件报1813错误
序: MS SQL Server 2008 r2附加无ldf日志的mdf数据库时报1813错误.提示数据库被强制分离,无日志不能还原之类的话. 可能的原因: 原因系统正在执行定时作业,没有主要到多次强 ...
- 使Python IDLE也变得高颜值
初学Python,大家应该都是用Python自带的IDLE了,我们可以让他颜值高一些,这样敲出的代码就赏心悦目,比如像下面这样: 我们首先要找到名为config-highlight.cfg的文件, ...
- archlinux 加载loop模块,且设定loop设备个数
如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...
- 5-sql查询
sql查询 一.Sql查询 1.查看表字段信息 用scott账户登陆 1).查看scott账户下的所有表 2).查看员工表字段信息 3).查看部门表字段信息 4).查看工资等级字段信息 2.查询表 1 ...
- 数据库Sharding系列文章
关于数据库Sharding的策略,有人整理出相关的方案,看完收获很大. 数据库分库分表(sharding)系列(五) 一种支持自由规划无须数据迁移和修改路由代码的Sharding扩容方案 数据库分库分 ...
- Hanoi问题java解法
用什么语言解法都差不多,思路都是一样,递归,这其中只要注重于开始和结果的状态就可以了,对于中间过程,并不需要深究.(我细细思考了一下,还是算了.=_=) 代码其实很简单注重的是思路. 问题描述:有一个 ...
- iOS多线程主题
下面是:2个并发进程.和2个并发线程的示意图: 下面介绍三种多线程技术(Thread.Cocoa Operation.Grand Central Dispatch): 1.最轻量级Thread(需要自 ...
- [LeetCode] Excel Sheet Column Title 求Excel表列名称
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...