JAVA中,求绝对值的函数是什么?

Python012

JAVA中,求绝对值的函数是什么?,第1张

函数:Math.java。

绝对值函数使用说明:

绝对值函数是JDK中Math.java中的实现方法,其用来得到表达式的绝对值。其实现非常简单,源码如下。

绝对值的特性及其运用:

1、正数的绝对值是其本身。

2、负数的绝对值是其相反数

3、零的绝对值是其本身。

绝对值:自减函数配合绝对值,先降序再升序。

//Math.abs方法是用来求绝对值的,如下:

import java.lang.*

public class MathDemo {

public static void main(String[] args) {

int x = 175

int y = -184

System.out.println("Math.abs(" + x + ")=" + Math.abs(x))

System.out.println("Math.abs(" + y + ")=" + Math.abs(y))

System.out.println("Math.abs(-0)=" + Math.abs(-0))

}

}

* Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API. <br>,程序如下:

public class Test {

public static void main(String[] args) {

for (int i = -5i <= 5i++) {

System.out.println(abs(i))*此句算出绝对值。调用下面的函数

}

}

public static int abs(int num)

{

return num * (1 - ((num >>>31)<<1))

}

}