Java笔记—Math类
来源:互联网 发布:矢量控制知乎 编辑:程序博客网 时间:2024/05/19 01:07
提供的常量:Math.PI,Math.E
Math类提供的一些常用的方法
public class BasicMathDemo{public static void main(String[] args) {double a = -191.635;double b = 43.74;int c = 16, d = 45;System.out.printf("The absolute value " + "of %.3f is %.3f%n", a,Math.abs(a));System.out.printf("The ceiling of " + "%.2f is %.0f%n", b, Math.ceil(b));System.out.printf("The floor of " + "%.2f is %.0f%n", b, Math.floor(b));System.out.printf("The rint of %.2f " + "is %.0f%n", b, Math.rint(b));System.out.printf("The max of %d and " + "%d is %d%n", c, d,Math.max(c, d));System.out.printf("The min of of %d " + "and %d is %d%n", c, d,Math.min(c, d));}}
public class ExponentialDemo {public static void main(String[] args) {double x = 11.635;double y = 2.76;System.out.printf("The value of " + "e is %.4f%n", Math.E);System.out.printf("exp(%.3f) " + "is %.3f%n", x, Math.exp(x));System.out.printf("log(%.3f) is " + "%.3f%n", x, Math.log(x));System.out.printf("pow(%.3f, %.3f) " + "is %.3f%n", x, y,Math.pow(x, y));System.out.printf("sqrt(%.3f) is " + "%.3f%n", x, Math.sqrt(x));}}
public class TrigonometricDemo {public static void main(String[] args) {double degrees = 45.0;double radians = Math.toRadians(degrees);System.out.format("The value of pi " + "is %.4f%n", Math.PI);System.out.format("The sine of %.1f " + "degrees is %.4f%n", degrees,Math.sin(radians));System.out.format("The cosine of %.1f " + "degrees is %.4f%n", degrees,Math.cos(radians));System.out.format("The tangent of %.1f " + "degrees is %.4f%n",degrees, Math.tan(radians));System.out.format("The arcsine of %.4f " + "is %.4f degrees %n",Math.sin(radians),Math.toDegrees(Math.asin(Math.sin(radians))));System.out.format("The arccosine of %.4f " + "is %.4f degrees %n",Math.cos(radians),Math.toDegrees(Math.acos(Math.cos(radians))));System.out.format("The arctangent of %.4f " + "is %.4f degrees %n",Math.tan(radians),Math.toDegrees(Math.atan(Math.tan(radians))));}}
Math.random()返回一个0.0~1.0之间的伪随机数
- Java笔记—Math类
- (27)Java学习笔记——常用对象 / Math 类
- Java学习笔记6——Math工具类
- Java数字格式化、Math类、随机数笔记
- Java.math学习笔记
- 【基础】java.math.Math类
- Java——Math类
- Java Math.round() ---学习笔记
- Java Math.round() ---学习笔记
- [学习笔记】Java Numbers类与Math类
- JavaSE学习笔记_17:Java-Math&Random类
- 正则表达式、Math、SimpleDateFromat、Calendar类+JAVA学习笔记-DAY14
- 学习笔记之java.math.bigdecimal类的精确计算
- 8.6-全栈Java笔记:Math类和枚举
- Java学习笔记(一)scanner.math.character类方法
- Java常用类——Math类
- Java——工具类Math
- java——Number 和 Math类
- 《大话数据结构》第7章.图
- Python解析XML简单介绍
- (转)腾讯微信技术总监周颢:一亿用户增长背后的架构秘密
- 反射
- linux内核
- Java笔记—Math类
- Exchange Server 2010 SP3正式发布
- linux 内核定时器详解
- (转)新浪微博技术架构分析-转载
- Java GUI中改变窗体的背影图片
- cookie使用
- HDU 4455
- Oracle中connect by...start with...的使用
- flex4动态加载样式文件即换肤