Question

Look at the following method. public static int test2(int x, int y) { if ( x...

Look at the following method.

public static int test2(int x, int y)
{
if ( x < y)
{
return -5;
}
else
{
return (test2(x - y, y + 5) + 6);
}
}

What is returned for test2(10, 20)?

Question 6 options:

a

1

b

10

c

6

d

-5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

d. -5

Add a comment
Know the answer?
Add Answer to:
Look at the following method. public static int test2(int x, int y) { if ( x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following method: public static int mystery (int x, double y, char ch) {              ...

    Consider the following method: public static int mystery (int x, double y, char ch) {               int u; if ('A' <= ch && ch <= 'R')                   return (2 * x + (int)(y)); else return((int)(2 * y) - x); } What is the output of the following Java statements? a. System.out.println (mystery(5, 4.3, 'B')); b. System.out.println (mystery(4, 9.7, 'v')); c. System.out.println (2 * mystery(6, 3.9, 'D'));

  • In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         .........

    In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         ......      }     public static void  main(String[] args)     {          int a, b;          ......          sample(a,b);     } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?

  • Which of the following is NOT part of the heading of the following method? public static...

    Which of the following is NOT part of the heading of the following method? public static int minimum(int x, int y) int smaller; if (x < y) smaller = x; else smaller = y; return smaller; C static C minimum(int x, int y) cint smaller; C public Consider the following method. public static int minimum(int x, int y) int smaller; if (x = y) smaller = x; else smaller = y; return smaller; Which of the following is a valid...

  • 24) (3x2 marks) Consider the following method: public static int mysteryl (int a, int b) (...

    24) (3x2 marks) Consider the following method: public static int mysteryl (int a, int b) ( int result 0: if (a <b) ( else if (a b) else ( return result: result mystery2 (a) mystery2 (a)i result - mystery2 (b) result-ab; public static int mystery2 (int x) f int countx for (int i 0; іск; i++) count +1: return counti What are the values stored in the variable result after the following method calls? a) int result mysteryl(4,1): b) int...

  • Consider the following method: Linel: public static int mystery(int n) { Line2: if (n < 10)...

    Consider the following method: Linel: public static int mystery(int n) { Line2: if (n < 10) { ine3: return n; Line4: } else { Line5: int a = n/10; Line 6: int b = n % 10; Line 7: return mystery(a + b); Line 8: } Line 9: } What is the result of the following call? System.out.println(mystery(648)); 18 8 12

  • Consider the following methods’ headers: public static int one(int a, char b, double c, String d)...

    Consider the following methods’ headers: public static int one(int a, char b, double c, String d) public static double two(double x, double y) public static char three(int r, int s, char t, double u) Answer the following questions: Q1) What is the signature of method one? Answer: Q2) What is the return type of method two? Answer: Q3) What the formal parameters of method three? Answer: Q4) How many actual parameters are needed to call the method three? Answer: Q5)...

  • Recursive Tracing. For each call to the following method, indicate what value is returned: public static...

    Recursive Tracing. For each call to the following method, indicate what value is returned: public static int mystery(int n) { if (n < 0) { return -mystery(-n); } else if (n == 0) { return 0; } else { return mystery(n / 10) * 10 + 9 - (n % 10); } Call Value Returned mystery(0) mystery(5) mystery(13) mystery(297) mystery(-3456) } Can any one help me with it?

  • Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a <...

    Programming 3_4: Write the method public static int rangeProduct(int a, int b). Assume that a < b. Your method must compute and return the product of the integers in the range from a to b. For example, if a = 3 and b = 6, your method would compute and return the product 3 × 4 × 5 × 6 = 360. public static int rangeProduct(int a, int b) {...}

  • 1. t(n) is the runtime of following function, public static int f4(int [] a, int start,...

    1. t(n) is the runtime of following function, public static int f4(int [] a, int start, int end){ int ans = 0; if (start >= end) ans = a[start]; else { int mid = (start + end) / 2; int x = f4(a, start, mid); int y = f4(a, mid + 1, end); print(a, start, end); //print each element in a from start to end if (x < y) ans = x; else ans = y; } return ans; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT