?? testmath.java
字號:
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestMath
{
public static void main(String[] args)
{
/*---------下面是三角運算---------*/
//將弧度轉換角度
System.out.println("Math.toDegrees(1.57):" + Math.toDegrees(1.57));
//將角度轉換為弧度
System.out.println("Math.toRadians(90):" + Math.toRadians(90));
//計算反余弦,返回的角度范圍在 0.0 到 pi 之間。
System.out.println("Math.acos(0.3):" + Math.acos(1.2));
//計算反正弦;返回的角度范圍在 -pi/2 到 pi/2 之間。
System.out.println("Math.asin(0.8):" + Math.asin(0.8));
//計算反正切;返回的角度范圍在 -pi/2 到 pi/2 之間。
System.out.println("Math.atan(2.3):" + Math.atan(2.3));
//計算三角余弦。
System.out.println("Math.cos(1.57):" + Math.cos(1.57));
//計算值的雙曲余弦。
System.out.println("Math.cosh(1.2 ):" + Math.cosh(1.2 ));
//計算正弦
System.out.println("Math.sin(1.57 ):" + Math.sin(1.57 ));
//計算雙曲正弦
System.out.println("Math.sinh(1.2 ):" + Math.sinh(1.2 ));
//計算三角正切
System.out.println("Math.tan(0.8 ):" + Math.tan(0.8 ));
//計算雙曲余弦
System.out.println("Math.tanh(2.1 ):" + Math.tanh(2.1 ));
//將矩形坐標 (x, y) 轉換成極坐標 (r, thet));,返回所得角 theta。
System.out.println("Math.atan2(0.1, 0.2):" + Math.atan2(0.1, 0.2));
/*---------下面是取整運算---------*/
//取整,返回小于目標數的最大整數。
System.out.println("Math.floor(-1.2 ):" + Math.floor(-1.2 ));
//取整,返回大于目標數的最小整數。
System.out.println("Math.ceil(1.2):" + Math.ceil(1.2));
//四舍五入取整
System.out.println("Math.round(2.3 ):" + Math.round(2.3 ));
/*---------下面是乘方、開方、指數運算---------*/
//計算平方根。
System.out.println("Math.sqrt(2.3 ):" + Math.sqrt(2.3 ));
//計算立方根。
System.out.println("Math.cbrt(9):" + Math.cbrt(9));
//返回歐拉數 e 的n次冪。
System.out.println("Math.exp(2):" + Math.exp(2));
//返回 sqrt(x2:" +y2),沒有中間溢出或下溢。
System.out.println("Math.hypot(4 , 4):" + Math.hypot(4 , 4));
// 按照 IEEE 754 標準的規定,對兩個參數進行余數運算。
System.out.println("Math.IEEEremainder(5 , 2):" + Math.IEEEremainder(5 , 2));
//計算乘方
System.out.println("Math.pow(3, 2):" + Math.pow(3, 2));
//計算自然對數
System.out.println("Math.log(12):" + Math.log(12));
//計算底數為 10 的對數。
System.out.println("Math.log10(9):" + Math.log10(9));
// 回參數與 1 之和的自然對數。
System.out.println("Math.log1p(9):" + Math.log1p(9));
/*---------下面是符號相關的運算---------*/
//計算絕對值。
System.out.println("Math.abs(-4.5):" + Math.abs(-4.5));
//符號賦值,返回帶有第二個浮點數符號的第一個浮點參數。
System.out.println("Math.copySign(1.2, -1.0):" + Math.copySign(1.2, -1.0));
//符號函數;如果參數為 0,則返回 0;如果參數大于 0,則返回 1.0;如果參數小于 0,則返回 -1.0。
System.out.println("Math.signum(2.3):" + Math.signum(2.3));
/*---------下面是大小相關的運算運算---------*/
//找出最大值
System.out.println("Math.max(2.3 , 4.5):" + Math.max(2.3 , 4.5));
//計算最小值
System.out.println("Math.min(1.2 , 3.4):" + Math.min(1.2 , 3.4));
//返回第一個參數和第二個參數之間與第一個參數相鄰的浮點數。
System.out.println("Math.nextAfter(1.2, 1.0):" + Math.nextAfter(1.2, 1.0));
//返回比目標數略大的浮點數
System.out.println("Math.nextUp(1.2 ):" + Math.nextUp(1.2 ));
//返回一個偽隨機數,該值大于等于 0.0 且小于 1.0。
System.out.println("Math.random():" + Math.random());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -