JAVA数学课及其方法|集1 JAVA本文讨论的数学类方法:
null
- abs(): JAVA数学abs() 方法返回传递的任何类型参数的绝对值。此方法可以处理所有数据类型。
- 特殊情况:
- 如果参数为正零或负零,则结果为正零。
- 如果参数为无穷大,则结果为正无穷大。
- 如果传递的参数为NaN,则结果为NaN。
语法:
public static datatype abs(datatype arg) Parameters: arg - the argument whose absolute value we need Returns: absolute value of the passed argument.
- acos(): JAVA数学acos() 方法返回传递参数的弧余弦值。 弧余弦是所传递参数的反余弦。 acos(arg)=cos -1 精氨酸 特殊情况: 如果参数为NaN或其绝对值大于1,则结果为NaN。 语法:
public static double acos(double a) Parameters: a - the argument whose arc cosine value we need. argument is taken as radian Returns: arc cosine value of the argument.
- 托拉迪亚斯(): JAVA数学托拉第安(双度) 方法将参数(度)转换为弧度。 特别点: 数学课通常把弧度作为输入,这在实际应用中非常不同,因为角度通常以度表示。 语法:
public static double toRadians(double deg) Parameters: deg - degree angle needs to be in radian. Returns: radians equivalent of the degree-argument passed.
什么是争论? 一个常数,包含一个double类型的Not-A-Number(NaN)值。它相当于Double返回的值。longBitsToDouble(0x7FF80000000000L)。
解释数学类中abs()、acos()和toRadians()方法的Java代码。
// Java program explaining Math class methods
// abs(), acos(), toRadians()
import
java.math.*;
public
class
NewClass
{
public
static
void
main(String[] args)
{
// Declaring the variables
int
Vali = -
1
;
float
Valf = .5f;
// Printing the values
System.out.println(
"Initial value of int : "
+Vali);
System.out.println(
"Initial value of int : "
+Valf);
// Use of .abs() method to get the absoluteValue
int
Absi = Math.abs(Vali);
float
Absf = Math.abs(Valf);
System.out.println(
"Absolute value of int : "
+Absi);
System.out.println(
"Absolute value of int : "
+Absf);
System.out.println(
""
);
// Use of acos() method
// Value greater than 1, so passing NaN
double
Acosi = Math.acos(
60
);
System.out.println(
"acos value of Acosi : "
+Acosi);
double
x = Math.PI;
// Use of toRadian() method
x = Math.toRadians(x);
double
Acosj = Math.acos(x);
System.out.println(
"acos value of Acosj : "
+Acosj);
}
}
输出:
Initial value of int : -1 Initial value of int : 0.5 Absolute value of int : 1 Absolute value of int : 0.5 acos value of Acosi : NaN acos value of Acosj : 1.5159376794536454
- addExact(): JAVA数学加法器(整数a,整数b) 方法返回传递的参数之和。 特别点: 如果结果溢出int或long(根据传递的参数),该方法将抛出算术异常。 语法:
public static int addExact(int x, int y) or public static long addExact(long x, long y) Parameters: a - first value b - second value Returns: Sum of the specified method arguments - a and b.
- asin(): JAVA数学asin() 方法返回传递的方法参数的arc sine值。返回角度在-pi/2到pi/2的范围内。 arc sine是所传递参数的反正弦。 asin(arg)=正弦 -1 精氨酸 特殊情况:
- 如果参数为NaN或其绝对值大于1,则结果为NaN。
- 如果参数为零,则结果为零。
语法:
public static double asin(double arg) Parameters: arg - argument passed. Returns: arc sine of the argument passed.
- cbrt(): JAVA数学cbrt() 方法返回传递的参数的立方根。 特别点:
- 如果参数为NaN,则结果为NaN。
- 如果参数为无穷大,则结果为与参数符号相同的无穷大。
- 如果参数为零,则结果为零。
语法:
public static double cbrt(double arg) Parameters: arg - argument passed. Returns: cube root of the argument passed
解释数学类中addExact()、asin()、cbrt()方法的Java代码。
// Java program explaining Math class methods
// addExact(), asin(), cbrt()
import
java.math.*;
public
class
NewClass
{
public
static
void
main(String[] args)
{
int
a =
1
, b =
8
;
// get the result of addExact method
int
radd = Math.addExact(a,b);
System.out.println(
"Using addExact() : "
+radd);
System.out.println(
""
);
// Use of acos() method
// Value greater than 1, so passing NaN
double
Asini = Math.asin(radd);
System.out.println(
"asin value of Asini : "
+Asini);
double
x = Math.PI;
// Use of toRadian() method
x = Math.toRadians(x);
double
Asinj = Math.asin(x);
System.out.println(
"asin value of Asinj : "
+Asinj);
System.out.println(
""
);
// Use of cbrt() method
double
cbrtval = Math.cbrt(
216
);
System.out.println(
"cube root : "
+cbrtval);
}
}
输出:
Using addExact() : 9 acos value of Asini : NaN acos value of Asinj : 0.054858647341251204 cube root : 6.0
- 地板(): JAVA数学楼层() 方法返回参数的下限值,即小于或等于传递参数的最接近整数值。 101.23的下限值为101 要点: 如果传递了NaN或无限参数,则会产生相同的参数。
Syntax: public static double floor(double arg) Parameters: arg - the argument whose floor value we need Returns:closest possible value that is either less than or equal to the argument passed
- hypot(): JAVA数学低血压(双p,双b) 方法将三角形的底面和垂直面作为参数传递时,返回直角三角形的斜边。 斜边=[垂直] 2. +基地 2. ] 1/2
要点:
- 如果其中一个参数是无限的,那么结果就是正无穷大。
- 如果任何一个参数都是NaN,并且两个参数都不是无限的,那么结果就是NaN。
Syntax: public static double hypot(double p, double b) Parameters: p - perpendicular of the right triangle b - base of the right triangle Returns: hypotenuse of the right triangle
- IEEEremainder(): JAVA数学IEEERemainder(双d1,双d2) 方法通过对两个参数w.r.t IEEE 754标准应用余数运算来返回余数值。 剩余值= d1–d2*n 哪里 n=d1/d2的最接近精确值
Syntax: public static double IEEEremainder(double d1,double d2) Parameters: d1 - dividend d2 - divisor Returns: remainder when f1(dividend) is divided by(divisor)
- log(): JAVA数学日志() 方法返回所传递参数的对数值。
Syntax: public static double log(double arg) Parameters: arg - argument passed. Returns: logarithmic value of the argument passed.
解释数学类中floor()、hypot()、IEEEremainder()和log()方法的Java代码。
// Java program explaining MATH class methods
// floor(), hypot(), IEEEremainder(), log()
import
java.lang.*;
public
class
NewClass
{
public
static
void
main(String[] args)
{
// Use of floor method
double
f1 =
30.56
, f2 = -
56.34
;
f1 =Math.floor(f1);
System.out.println(
"Floor value of f1 : "
+f1);
f2 =Math.floor(f2);
System.out.println(
"Floor value of f2 : "
+f2);
System.out.println(
""
);
// Use of hypot() method
double
p =
12
, b = -
5
;
double
h = Math.hypot(p, b);
System.out.println(
"Hypotenuse : "
+h);
System.out.println(
""
);
// Use of IEEEremainder() method
double
d1 =
105
, d2 =
2
;
double
r = Math.IEEEremainder(d1,d2);
System.out.println(
"Remainder : "
+r);
System.out.println(
""
);
// Use of log() method
double
l =
10
;
l = Math.log(l);
System.out.println(
"Log value of 10 : "
+l);
}
}
输出:
Floor value of f1 : 30.0 Floor value of f2 : -57.0 Hypotenuse : 13.0 Remainder : 1.0 Log value of 10 : 2.302585092994046
本文由 莫希特·古普塔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END