Question

3) Consider the following recursive method, what will be the output for the following method calls? Explain. (25 pts.) public static void sample (int number) if (number < 0) { System.out.println( superwriteVertical (-number); System.out.println(number); superwriteVertical (number/ 10); else if (number 10) else ( System.out.print1n(number % 18); sample(-100); sample(50); sample(1024);
0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
3) Consider the following recursive method, what will be the output for the following method calls?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • 3. Determine the general result (in terms of n) of the following recursive function (4 pts.)...

    3. Determine the general result (in terms of n) of the following recursive function (4 pts.)               public static void func2(int n)      {         if(n == 1)            System.out.println(“*”);         else         {            for (int i = 1; i <= n; i++)               System.out.print(“*”);            System.out.println();            func2(n-1);                      }               } 4. Does func2 above perform down or bottom up computation? ___________________ (2 pts.)

  • (20 pts) Fill in the missing code: This recursive method returns “even” if the length of...

    (20 pts) Fill in the missing code: This recursive method returns “even” if the length of a give String is even, and “odd” if the length of the String is odd. public static String foo(String s) { if (s.length() ==0)    return “even”; else if (s.length() = = 1)    return “odd”; else     //your code goes here } (40 pts) You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n)...

  • Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...

    Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...

  • on 2 Consider the following recursive method test: public static int test(String s, int last) if...

    on 2 Consider the following recursive method test: public static int test(String s, int last) if (last < 0) { return 0; if (s.charAt(last) == 0) { return 2 - test(s, last - 1); return 1 + 2 test(s, last - 1); What is the output of: test("11001", 4). TTT Arial 3 (12pt) - TEE 25

  • 1. Determine what the following function calls return for recursive function func below.     (4 pts.)...

    1. Determine what the following function calls return for recursive function func below.     (4 pts.)               public static int func(int n)      {         if(n == 1)            return 2;         else            return 2 + func(n-1);                      (a) func(1) = ________        (b) func(4) = ________ 2. Does func above perform top down or bottom up computation? ____________ (2 pts.)

  • I am in an entry-level Java class and need assistance solving questions 20-25 for a homework...

    I am in an entry-level Java class and need assistance solving questions 20-25 for a homework assignment. Any help is appreciated. Thank you. Q20 Read the code and answer the question 6 Points Read each of the following code snippets and determine if they are equivalent. I.e. they produce the same output. Q20.1 Are these snippets equivalent? 2 Points Snippet 1: int i=0; while (i<10) System.cut.print(i); i++; 1 Snippet 2: for(int i-0; i<10; i++) System.out.print(i); } Yes O No Q20.2...

  • The following recursive method factRecursive computes the factorial of positive integer n. Demonstrate that this method...

    The following recursive method factRecursive computes the factorial of positive integer n. Demonstrate that this method is recursive. public static int factRecursive(int n) { int result = 0; if (n == 0) { result = 1; } else { result = n * factRecursive(n - 1); } return result; }

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • 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...

  • Write the output produced when the following method is passed each of the following lists and...

    Write the output produced when the following method is passed each of the following lists and give the formal code for the problem: public static void mystery1(ArrayList<Integer> list) { for (int i = list.size() - 1; i > 0; i--) { if (list.get(i) < list.get(i - 1)) { int element = list.get(i); list.remove(i); list.add(0, element); } } System.out.println(list); } a. [2, 6, 1, 8] b. [30, 20, 10, 60, 50, 40]

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
ADVERTISEMENT