Use the Math.abs and Math.signnum methods to force the sign of one variable to match the sign of another - Java Language Basics

Java examples for Language Basics:Math

Description

Use the Math.abs and Math.signnum methods to force the sign of one variable to match the sign of another

Demo Code

public class Main {
  public static void main(String[] args) {
    int a = 27;//from  w ww . j av  a2s.c o m
    int b = -32;
    float f = Math.abs(a) * Math.signum(b);   // a is  now -27;

    System.out.println(f);

  }

}

Related Tutorials