Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complet one line code 1 Complete the following recursive implementation of the max method. For input 5 2 6 7 9 1 3 2 11

complet one line code

1 Complete the following recursive implementation of the max method. For input

5 2 6 7 9 1 3 2 11 15 29 21 13

public class Test {

public static void main(String[] args) { Scanner stdin = new Scanner(System.in);

int[] vals = new int[30]; int cnt = 0;

while (stdin.hasNextInt()) { vals[cnt++] = stdin.nextInt(); }

System.out.println(max(vals, cnt - 1)); stdin.close(); }

public static int max(int[] vals, int end) {

int res; // your code starts here

// your code ends here

System.out.println(res); return res; }

}

2. Complete the following recursive implementation of the longest to find the longest string in an array. For input

All the pppproposals have been loaded into BB for your review. Let me know if you have questions.

public class Test {

public static void main(String[] args) { Scanner stdin = new Scanner(System.in);

String[] vals = new String[30]; int cnt = 0;

while (stdin.hasNext()) { vals[cnt++] = stdin.next(); }

System.out.println(longest(vals, cnt - 1)); stdin.close(); }

public static String longest(String[] vals, int end) {

String res; // your code starts here

// your code ends here

System.out.println(res); return res; }

}

3. Complete the following recursive implementation of the factorial method. Pay attention to your base case, your program should output

1 1 1 3 2 1 1 2 6 6 6 5 4 3 2 1 1 2 6 24 120 720 720

public class Test {

public static void main(String[] args) { System.out.println(factorial(1)); System.out.println(factorial(3)); System.out.println(factorial(6)); }

public static int factorial(int n) { System.out.println(n);

int res; // your code starts here

// your code ends here

System.out.println(res); return res; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Google Analytics 4 The Data Driven Marketing Revolution

Authors: Galen Poll

2024th Edition

B0CRK92F5F, 979-8873956234

More Books

Students also viewed these Databases questions

Question

Describe what is known about thinking in other species.

Answered: 1 week ago

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago