Showing posts with label absolute value. Show all posts
Showing posts with label absolute value. Show all posts

Wednesday, 21 January 2015

Find absolute value of any number

the absolute value (or modulus) |x| of a real number x is the non-negative value of x without regard to its sign.
If number is less than zero return -(number) otherwise return number

public class OwnAbsoluteFunction {
   
     static int getAbsolute(int i){
          return(i>0?i:-i);
     }
    
     public static void main(String[] args) {
          int i=-10;
        System.out.println("i="+getAbsolute(i));
     }
    
}