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]
2 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]2 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
How do you hack a iPhone, Like If you forgot your password and want to get back in your phone. What do you do?
s344n2d4d5 [400]

Answer:

fix it on itunes

Explanation:

or get a new one

6 0
3 years ago
Read 2 more answers
Gathering information with your eyes is called
Ivahew [28]
Observing, Looking, Collecting, there are a few words for "gathering information with your eyes". 
4 0
3 years ago
Read 2 more answers
What does the term hardware refer to?
Jobisdone [24]

Answer:

The physical components that a computer is made of

Explanation:

as u can see these components and u can repaire these components if they got damaged

6 0
3 years ago
What service converts ip addresses into more recognizable alphanumeric names??
tresset_1 [31]
I think is DNS..........
6 0
3 years ago
The appropriate length for an e-mail is about half the amount of text that will fit on an 8 1/2' by 11' page.
lys-0071 [83]

Wrong..............................................

7 0
2 years ago
Read 2 more answers
Other questions:
  • Did you see the fire, uh, fireworks last night? Which of the following sentences is the most correct way to format this accordin
    15·2 answers
  • Using the _____ model brings sellers and buyers together on the web and collects commissions on transactions between these parti
    5·1 answer
  • . The first step in devising security services and mechanisms is to develop a security policy True False
    11·1 answer
  • Linda wants to apply for a job in a company of her choice. Which information would her potential employers likely review in her
    10·2 answers
  • 15 points. Please give an actual answer and not some random thing. this is not just free points. Correct answer will receive bra
    12·2 answers
  • Which engineer may design a GPS for a vehicle?
    15·1 answer
  • Add me on Fortn!te <br> TsarBacon (imma girl)
    11·1 answer
  • GIVING BRAINLIEST
    15·1 answer
  • Please can someone solve this question<br>What is a software and types of software​
    11·1 answer
  • Award documentation is typically required to be prepared and submitted within how long after the end of a project period:_____.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!