Consider the following method, which is intended to return the product of 3 and the nonnegative difference between two int parameters.

public int threeTimesDiff(int num1, int num2) {

return 3 * (num1 - num2);

}
Which precondition is required so that the method works as intended for all values of the parameters that satisfy the precondition?
A. num1 > 0, num2 > 0
B. num1 >= 0, num2 >= 0
C. num1 >= num2
D. num2 >= num1

Respuesta :

Methods are code segments that are executed when called or evoked.

The required precondition for the method to work as intended is (c) num1 >= num2

The return value of the method is given as:

3 * (num1 - num2).

The return value is said to be non-negative.

So, the following condition must be true

[tex]3 \times (num1 - num2) \ge 0[/tex]

Divide both sides of the equation by 3

[tex](num1 - num2) \ge 0[/tex]

Remove the bracket

[tex]num1 - num2 \ge 0[/tex]

Add num2 to both sides of the equation

[tex]num1 \ge num2[/tex]

Hence, the required precondition for the method to work as intended is (c) num1 >= num2

Read more about preconditions at:

https://brainly.com/question/13795586

ACCESS MORE