Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (20 pts) Given the following code: public static void foo3(String s) { if (s.length() >0) { System.out.print(s.charAt(s.length() -1)); foo3(s.substring(0, s.length() -1)); } } What

1. (20 pts) Given the following code:

public static void foo3(String s) {

if (s.length() >0) {

System.out.print(s.charAt(s.length() -1)); foo3(s.substring(0, s.length() -1)); } }

What is the output of: foo3();

2. (20 pts) Using the code in #1,

What is the output of foo3(Hi)?

3. (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 }

4. (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) //line 9 { if (n = = 0) return 1; else System.out.println(n* foo(n-1) ); } //line 15 At compile time, you get the following error: Text.java: 15: missing return statement } //line 15 ^ 1 error

Explain what the problem is and how to fix it.

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_2

Step: 3

blur-text-image_3

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

1. The partnership paid Joseph cash for his share of the equity.

Answered: 1 week ago

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago

Question

Effective Delivery Effective

Answered: 1 week ago