Question #306606

A method called absoluteValue, which takes as its only parameter a value of type double, and

returns a value of type double. The parameter represents an arbitrary number, and the value returned

by the method represents the absolute value of this arbitrary number. The absolute value of a number

x, denoted |x|, is x if x is greater than or equal to 0, and -x if x is less than 0. For example, suppose the

following method call is executed:

double value = MathAssignment.absoluteValue(-42.0);

After the execution of the above method call, the value stored in variable value will be 42.0, as the

absolute value of -42 is 42.

3. Now write the main method and call both methods with appropriate arguments. Make sure that you

call both methods with enough valid values to show their


Expert's answer

public class MathAssignment{


  public static void main(String args[]) {


        double value = MathAssignment.absoluteValue(Integer.parseInt(args[0]));
        System.out.println(value);
  }
  
  
    static double absoluteValue(double assignment){
        
        if(assignment < 0){
            return assignment * -1;
        }
        return assignment;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS