JAVAlang.Java中的数学课|集1

数学类方法有助于执行数值运算,如平方、平方根、立方体、立方根、指数和三角运算

null

宣言:

public final class Math   extends Object

什么是争论? 一个常数,包含一个double类型的Not-A-Number(NaN)值。它相当于Double返回的值。longBitsToDouble(0x7FF80000000000L)。

lang.math课程的方法:

1.abs():java。朗,数学。abs() 方法返回传递的任何类型参数的绝对值。此方法可以处理所有数据类型。

  • 如果参数为正零或负零,则结果为正零。
  • 如果参数为无穷大,则结果为正无穷大。
  • 如果传递的参数为NaN,则结果为NaN。

语法:

public static datatype abs(datatype arg)Parameters:arg - the argument whose absolute value we needReturns:absolute value of the passed argument.

2.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.

3.toRadians():java。朗,数学。托拉第安(双度) 方法将参数(度)转换为弧度。 注: 数学课通常把弧度作为输入,这在实际应用中非常不同,因为角度通常以度表示。

语法:

public static double toRadians(double deg)Parameters:deg - degree angle needs to be in radian.Returns:radians equivalent of the degree-argument passed.

解释lang.Math类中abs()、acos()和toRadians()方法的Java代码。

JAVA

// Java program explaining lang.Math class methods
// abs(), acos(), toRadians()
import java.lang.*;
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  : -1Initial value of int  : 0.5Absolute value of int : 1Absolute value of int : 0.5acos value of Acosi : NaNacos value of Acosj : 1.5159376794536454

4.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.

5.cbrt():java。朗,数学。cbrt() 方法返回传递的参数的立方根。 特别点:

  • 如果参数为NaN,则结果为NaN。
  • 如果参数为无穷大,则结果为与参数符号相同的无穷大。
  • 如果参数为零,则结果为零。

语法:

public static double cbrt(double arg)Parameters:arg - argument passed. Returns:cube root of the argument passed

解释lang.Math类中asin()、cbrt()方法的Java代码。

JAVA

// Java program explaining lang.Math class methods
// asin(), cbrt()
import java.lang.*;
public class NewClass
{
public static void main(String[] args)
{
int a = 1 , b = 8 ;
int radd = a+b;
// Use of asin() 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);
}
}


输出:

asin value of Asini : NaNasin value of Asinj : 0.054858647341251204cube root : 6.0

6.floor():java。朗,数学。楼层() 方法返回参数的下限值,即小于或等于传递参数的最接近整数值。 101.23的下限值为101

要点: 如果传递了NaN或无限参数,则会产生相同的参数。

Syntax:public static double floor(double arg)Parameters:arg - the argument whose floor value we needReturns:closest possible value that is either less than                 or equal to the argument passed

7.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 triangleb - base of the right triangleReturns:hypotenuse of the right triangle

8.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 - divisorReturns:remainder when f1(dividend) is divided by(divisor)

9.log():java。朗,数学。日志() 方法返回所传递参数的对数值。

Syntax:public static double log(double arg)Parameters:arg - argument passed. Returns:logarithmic value of the argument passed.

解释lang.Math类中floor()、hypot()、IEEEremainder()和log()方法的Java代码。

JAVA

// Java program explaining lang.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.0Floor value of f2 : -57.0Hypotenuse : 13.0Remainder : 1.0Log value of 10 : 2.302585092994046

10.ceil():java。朗,数学。ceil(双a) 方法返回可能大于或等于传递的参数的最小值。返回的值是一个数学整数。

  • 如果返回值已经是一个数学整数,则结果相同。
  • 如果传递的参数为NaN、无限或零,则结果相同。
  • 如果传递的参数小于零但大于-1.0,则结果为负零

语法:

public static double ceil(double arg)Parameters:arg - the argument valueReturns:smallest possible value(mathematical integer)which is either greater or equal to the argument passed

11.atan():java。朗,数学。阿坦() 方法返回方法参数值的反正切。返回的角度在-pi/2到pi/2的范围内。 arc tan与通过的论点相反。 atan(arg)=arg的tan倒数

特殊情况:

  • 如果传递的参数为NaN或其绝对值大于1,则结果为NaN。
  • 如果参数为零,则结果为零。

语法:

public static double atan(double a)Parameters:a - the argument whose arc tangent value we need.    argument is taken as radianReturns:arc tan value of the argument.

12.copySign():java。朗,数学。copySign() 方法返回第一个浮点参数,但具有第二个参数的符号。

语法:

public static double copySign(double m, double s)                    orpublic static float copySign(float m, float s)Parameters:m - magnitude s - sign Returns:returns first argument with sign of second floating-point argument.

解释lang.Math类中atan()、ceil()和copySign()方法的Java代码。

JAVA

// Java program explaining lang.Math class methods
// atan(), ceil(), copySign()
import java.math.*;
public class NewClass
{
public static void main(String[] args)
{
// Use of atan() method
double Atani = Math.atan( 0 );
System.out.println( "atan value of Atani : " +Atani);
double x = Math.PI/ 2 ;
// Use of toRadian() method
x = Math.toRadians(x);
double Atanj = Math.atan(x);
System.out.println( "atan value of Atanj : " +Atanj);
System.out.println( "" );
// Use of ceil() method
double val = 15.34 ,ceilval;
ceilval = Math.ceil(val);
System.out.println( "ceil value of val : " +ceilval);
System.out.println( "" );
double dblMag = val;
double dblSign1 = 3 ;
double dblSign2 = - 3 ;
// Use of copySign() method
double result1 = Math.copySign(dblMag,dblSign1);
System.out.println( "copySign1 : " +result1);
double result2 = Math.copySign(dblMag,dblSign2);
System.out.println( "copySign2 : " +result2);
}
}


输出:

atan value of Atani : 0.0atan value of Atanj : 0.0274087022410345ceil value of val : 16.0copySign1 : 15.34copySign2 : -15.34

下一篇文章 : JAVAlang.math |第二组

本文由 莫希特·古普塔(Mohit Gupta_OMG) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享