java math abs
数学课静态长abs(长l) (Math Class static long abs(long l))
-
This method is available in java.lang package.
此方法在java.lang包中可用。
-
This method is used to return the absolute value of the given parameter in the method.
此方法用于返回方法中给定参数的绝对值。
-
This is a static method so this method is accessible with classname too.
这是一个静态方法,因此也可以使用类名访问此方法。
-
The return type of this method depends on given argument datatype and here we are passing long data type in the method that means the return type of this method is long.
此方法的返回类型取决于给定的参数数据类型,此处我们在该方法中传递long数据类型,这意味着该方法的返回类型为long。
-
In this method, we pass only one parameter as an argument in the method of Math class.
在此方法中,我们仅将一个参数作为参数传递给Math类的方法。
-
This method does not throw any exception.
此方法不会引发任何异常。
-
In this method, if the given argument is equal to the value of long.MIN_VALUE it returns the same negative value.
在此方法中,如果给定参数等于long.MIN_VALUE的值, 则它将返回相同的负值。
-
This is an overridable method so various versions of this method are available but here we are looking long datatype argument so the following syntax is given below,
这是一个可重写的方法,因此可以使用该方法的各种版本,但是在这里我们正在寻找long数据类型参数,因此以下语法如下:
Syntax:
句法:
public static long abs(long l){
}
Parameter(s):
参数:
long l – a long value whose absolute value to be found.
long l-一个要确定其绝对值的long值。
Return value:
返回值:
The return type of this method is long, returns absolute value as a long.
该方法的返回类型为long ,将绝对值返回为long。
Note:
注意:
-
If we pass a positive long integer, it returns the same value.
如果我们传递一个正长整数,它将返回相同的值。
-
If we pass a negative long integer, it returns the value without sign i.e. it returns the positive long integer.
如果我们传递一个负长整数,它将返回不带符号的值,即它将返回正长整数。
-
If we pass positive zero (0) or negative zero (-0), it returns zero without sign (0).
如果我们传递正零(0)或负零(-0),则它将返回零而没有符号(0)。
-
If we pass an infinity parameter, it returns exception.
如果我们传递一个无穷大参数,它将返回异常。
-
If we pass “NaN” (Not A Number), it returns the same i.e. a “NaN”.
如果我们传递“ NaN”(非数字),则返回相同的值,即“ NaN”。
演示abs(long l)方法示例的Java程序 (Java program to demonstrate example of abs(long l) method)
// Java program to demonstrate the example of
// abs(long l) method of Math class
class AbsLongTypeMethod {
public static void main(String[] args) {
// We are declaring few variables
long a = 123121l;
long b = -123121l;
long c = 0l;
long d = -0l;
/*
long e = 74587l/0l;
long f = -7458l/0l;
*/
// By using abs(long l) method we will find the
// absolute value of given parameter in the method
System.out.println("The absolute value of a is : " + Math.abs(a));
System.out.println("The absolute value of b is : " + Math.abs(b));
System.out.println("The absolute value of c is : " + Math.abs(c));
System.out.println("The absolute value of d is : " + Math.abs(d));
/*
// In the below code exception will be thrown
// because we are passing infinity
System.out.println("The absolute value of e is : "+Math.abs(e));
System.out.println("The absolute value of f is : "+Math.abs(f));
*/
}
}
Output
输出量
E:\Programs>javac AbsLongTypeMethod.java
E:\Programs>java AbsLongTypeMethod
The absolute value of a is : 123121
The absolute value of b is : 123121
The absolute value of c is : 0
The absolute value of d is : 0
翻译自: https://www.includehelp.com/java/math-class-static-long-abs-long-l-method-with-example.aspx
java math abs
今天的文章java中静态常量的编写方式_python math库分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/84456.html