9.5k views
3 votes
Write a function template that accepts an argument and returns its absolute value. The absolute value of a number is its value with no sign. For example, the absolute value of -5 is 5, and the absolute value of 2 is 2. Test the template in a simple driver program being sure to send the template short, int, double, float, and long data values.

1 Answer

4 votes

Answer:

The function in Java is as follows:

public static double func(double num){

num = Math.abs(num);

return num;

}

Step-by-step explanation:

This defines the function

public static double func(double num){

This determines the absolute function of num

num = Math.abs(num);

This returns the calculated absolute value

return num;

}

User Kiewic
by
4.8k points