Java笔记—Math类

提供的常量: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之间的伪随机数

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值