Example usage for java.lang Math abs

List of usage examples for java.lang Math abs

Introduction

In this page you can find the example usage for java.lang Math abs.

Prototype

@HotSpotIntrinsicCandidate
public static double abs(double a) 

Source Link

Document

Returns the absolute value of a double value.

Usage

From source file:SquareRoot.java

public static void main(String[] args) {
    System.out.println(Math.abs(1 - 100));
}

From source file:Main.java

public static void main(String[] args) {
    int x = 123;/*from  ww w  .  j a  va 2 s .co m*/
    int y = -123;

    System.out.println(Math.abs(x));
    System.out.println(Math.abs(y));
    System.out.println(Math.abs(-0));
}

From source file:Main.java

public static void main(String[] argv) {

    Random r = new Random();
    int randint = Math.abs(r.nextInt()) % 11;
    System.out.println(randint);/*from w  w w  .  j  a va  2  s.c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    double x = 2.1d;
    double y = -0.12345d;

    System.out.println(Math.abs(x));
    System.out.println(Math.abs(y));
    System.out.println(Math.abs(-9.5));
}

From source file:Main.java

public static void main(String[] args) {

    float x = 1.2345f;
    float y = -123.45f;

    System.out.println(Math.abs(x));
    System.out.println(Math.abs(y));
    System.out.println(Math.abs(-123.0f));
}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7));
    System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0));
    System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7));
    System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2));
    System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8));
    System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0));
    System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0));
    System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0));
    System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2));
    System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8));
    System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E));
    System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E));
    System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7));
    System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7));
    System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7));
    System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7));
    System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0));
    System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5));
    System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0));
    System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0));
    System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0));
    System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0));
}

From source file:Main.java

public static void main(String[] args) {
    long x = 12345678901234L;
    long y = -12345678901234L;

    System.out.println(Math.abs(x));
    System.out.println(Math.abs(y));
    System.out.println(Math.abs(-18885785959l));
}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.println("Absolute value of -18 is " + Math.abs(-18));
}

From source file:Main.java

public static void main(String[] args) {
    int i = 8;//from  ww  w.  j  av a2  s  . co  m
    int j = -5;
    System.out.println("Absolute value of " + i + " is :" + Math.abs(i));
    System.out.println("Absolute value of " + j + " is :" + Math.abs(j));

    float f1 = 1.40f;
    float f2 = -5.28f;
    System.out.println("Absolute value of " + f1 + " is :" + Math.abs(f1));
    System.out.println("Absolute value of " + f2 + " is :" + Math.abs(f2));

    double d1 = 3.324;
    double d2 = -9.324;
    System.out.println("Absolute value of " + d1 + " is :" + Math.abs(d1));
    System.out.println("Absolute value of " + d2 + " is :" + Math.abs(d2));

    long l1 = 3L;
    long l2 = -4L;
    System.out.println("Absolute value of " + l1 + " is :" + Math.abs(l1));
    System.out.println("Absolute value of " + l2 + " is :" + Math.abs(l2));
}

From source file:Main.java

public static void main(String[] args) {
    int a = 10;//from  w  w w  . jav  a2s  . c om
    int b = -50;
    int c = 3;
    double x = 25.0;
    double y = 3.0;
    double z = 4.0;

    System.out.println("abs(b)     = " + Math.abs(b));
    System.out.println("cbrt(x)   = " + Math.cbrt(x));
    System.out.println("exp(y)     = " + Math.exp(z));
    System.out.println("hypot(y, z)= " + Math.hypot(y, z));

    System.out.println("log(y)    = " + Math.log(y));
    System.out.println("log10(y)  = " + Math.log10(y));
    System.out.println("max(a, b) = " + Math.max(a, b));
    System.out.println("min(a, b) = " + Math.min(a, b));
    System.out.println("pow(a, c) = " + Math.pow(a, c));
    System.out.println("random()  = " + Math.random());
    System.out.println("signum(b) = " + Math.signum(b));
    System.out.println("sqrt(x)   = " + Math.sqrt(y));
}