Consider the following method: public static boolean tryIt (int a, int b) { if ( (a - b) == Math.abs(a - b)) return true; return false; } Which of the following methods produce the same results?

I. public static boolean tryIt (int a, int b) { if (a > b) return true; return false; }
II. public static boolean tryIt (int a, int b) { if (a == b) return true; return false; }
III. public static boolean tryIt (int a, int b) { if (a >= b) return true; return false; } I, II, and III III only II only I and II I only

Respuesta :

Answer:

III only

Step-by-step explanation:

Let us consider the case

  1. when (a >b) , at a>b the given method will produce true. Now I & III will give true, but II will return false.
  2. when (a==b) , the given method will produce true. Now II and III will give true and I will give false.

Conclusion

it is concluded that in both the conditions, only III will generate the same results as the given method, Thus ONLY III is the right answer