Answer to Question #301777 in Java | JSP | JSF for Hanif

Question #301777

The Math class, which is part of the Java standard class library, provides various class methods that perform

common calculations, such as trigonometric functions.

Write a class called MathAssignment, which provides some of the functionality which is also provided by

the Math class. This class should define the static methods described below:

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.


1
Expert's answer
2022-02-24T04:24:10-0500
public class MathAssignment {

public static double absoluteValue(double value){

double absoluteValue;

if(value >= 0){

absoluteValue = value;

}
else{

absoluteValue = -value;

}

return absoluteValue;

}

} 

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS