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 |
Look at the following method. public static int test2(int x, int y) { if ( x...
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 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) ( 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) { 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) 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 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 < 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, 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; }...
1. Look at the following pseudocode algorithm. package javaapplication292 public class JavaApplication292 ( public static void main(StringlI args) recFun(258); public static void recFun( int x) if (x > 10) recFun (x/10); System.out. printIn( x % 10 ); else System.out.println(x); What is the output of the following statements? a. recFun(258); b. recFun (7);