tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Core > Integer > Signum Function

Signum Function 

The following example shows how to use signum function. It is useful to provide a return value in comparison functions for sorting.

File Name  :  
com/bethecoder/tutorials/core/integer/IntegerSignum.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.core.integer;

public class IntegerSignum {

  /**
   @param args
   */
  public static void main(String[] args) {

    /**
     * It returns one of the following values,
     *  -1 if the specified value is negative
     *    0 if the specified value is zero 
     *   1 if the specified value is positive
     */
    System.out.println(Integer.signum(-20));
    System.out.println(Integer.signum(-20000000));
    System.out.println(Integer.signum(0));
    System.out.println(Integer.signum(20000000));
    System.out.println(Integer.signum(20));
  }

}
   

It gives the following output,
-1
-1
0
1
1



 
  


  
bl  br