1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gemiola [76]
3 years ago
13

Debug the recursive reverseString method, which is intended to return the input String str reversed (i.e. the same characters bu

t in reverse order).
Use the runner class to test this method but do not write your own main method or your code will not be graded correctly.
public class U10_L2_Activity_One
{
public static String reverseString(String str)
{
if (str.length() < 0)
{
return str;
}
s = reverseString(str.substring(2)) + str.substring(0,1);
}
}
Runner's code (don't change):
import java.util.Scanner;
public class runner_U10_L2_Activity_One
{
public static void main(String[] args)
{
System.out.println("Enter string:");
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
System.out.println("Reversed String: " + U10_L2_Activity_One.reverseString(s));
}
}
Computers and Technology
1 answer:
Nady [450]3 years ago
7 0

Answer:

Explanation:

The following modified code correctly uses recurssion to reverse the string that was passed as a parameter to the reverseString method. A test output using the runner class can be seen in the attached image below.

import java.util.Scanner;

class U10_L2_Activity_One {

   public static String reverseString(String str) {

       if (str.isEmpty()) {

           return str;

       }

       return reverseString(str.substring(1)) + str.charAt(0);

   }

}

class runner_U10_L2_Activity_One

{

   public static void main(String[] args)

   {

       System.out.println("Enter string:");

       Scanner scan = new Scanner(System.in);

       String s = scan.nextLine();

       System.out.println("Reversed String: " + U10_L2_Activity_One.reverseString(s));

   }

}

You might be interested in
I Previous
Tcecarenko [31]

Answer:

D. Change the def to def area (width, height = 12)

Explanation:

Required

Update the function to set height to 12 when height is not passed

To do this, we simply update the def function to:

def area (width, height = 12)

So:

In boxlarea = area (5,2), the area will be calculated as:

area = 5 * 2 = 10

In box2area = area (6), where height is not passed, the area will be calculated as:

area = 6 * 12 = 72

5 0
2 years ago
Narrate an incident from the experience of a 14 year old girl which brings out the message: " Never leave till tomorrow what you
pogonyaev
Smth called google turbo record United in
7 0
3 years ago
Write a declaration of a variable named count that can be used to hold numbers like 90000 and -1 and -406.
Andreyy89
Which language? In Java it would simply be:

int count;
7 0
2 years ago
Columns can be added to a page in the page layout tab in the blank grouping
ZanzabumX [31]

Answer:

Page Setup Grouping.

Explanation:

In Microsoft Word, Columns break up the page into, at max, 13 columns, and at minumum, 2. The way you go about doing this is

  1. Go to the Layout Tab
  2. Go to the Page setup Grouping
  3. Click on the Columns Action
  4. In the Dialog Box, choose either from one of the presents, or custom make your own column settings.
  5. Click Okay
  6. Done!

3 0
3 years ago
Read 2 more answers
Which of the following is a good choice to help you stay organized when you are away from the office? A. Personal Information ma
Free_Kalibri [48]

Answer:

A

Explanation:

6 0
3 years ago
Other questions:
  • In your presentation you added a text box to?
    5·1 answer
  • If you want to prioritize downloads of your mobile app instead of visits to your mobile site, you should: a) add a sitelink exte
    10·1 answer
  • How do you uninstall sc update?
    13·2 answers
  • Write a method that will receive 2 numbers as parameters and will return a string containing the pattern based on those two numb
    10·1 answer
  • (EASY 15 POINTS) What are two indications in a browser that a secure connection is being used?
    6·1 answer
  • If given the chance to own manage a business,what will be the name of the business?
    11·2 answers
  • Another pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect
    13·1 answer
  • What is modularity? Help asap
    9·1 answer
  • What describes a group of cells?<br> O crowd<br> Orange<br> O set<br> gangle
    7·2 answers
  • You are a network administrator for your company. The network consists of a single Active Directory domain. All servers run Wind
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!