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
If you cause a car accident, which type of insurance will require you to pay the least out of pocket?
balu736 [363]

High deductible plan is referred to those insurance plans in which an individual has to pay the least out of their pocket and in return, the claim amount is more.

It is somewhat similar to traditional healthcare insurance but it too has slight differences.


7 0
3 years ago
Read 2 more answers
How to convert binary to decimal <br> Please it’s so hard and what is digital and analogue
geniusboy [140]

Answer:

How to convert binary to decimal ?

It consists of digits from 0 to 9. Binary to decimal conversion can be done in the simplest way by adding the products of each binary digit with its weight (which is of the form - binary digit × 2 raised to a power of the position of the digit) starting from the right-most digit which has a weight of 20.

what is digital and analogue?

In analog technology, a wave is recorded or used in its original form. So, for example, in an analog tape recorder, a signal is taken straight from the microphone and laid onto tape.In digital technology, the analog wave is sampled at some interval, and then turned into numbers that are stored in the digital device.

8 0
3 years ago
SOMEONE PLZZ HELP ME ASAP!!
Sever21 [200]

C

because you have to re read it

8 0
3 years ago
Read 2 more answers
What is the effect of flattening layers in image editing?
PolarNik [594]
The answer to this blanks are black and visible
6 0
2 years ago
Read 2 more answers
There are many careers within the IT industry. _____ are responsible for organizing a company's data, making sure all the data i
devlian [24]
C. database administrators are responsible for organizing a company's data making sure all the data is accurate' available' and secure
5 0
3 years ago
Other questions:
  • Drag the correct type of update to its definition.
    5·1 answer
  • Can i earn money at weegy.com ?
    10·1 answer
  • Think of a game you are familiar with and identify at least three team responsibilities which were required to make the game, on
    5·1 answer
  • Liz's meeting is scheduled to end at 9:30. It is 9:20 and team
    9·1 answer
  • 1. A tachometer measures:
    8·1 answer
  • A browser is used for creating Web pages. true or false?
    5·2 answers
  • Describe the components of a CPU--the CU, ALU, and Cache--and explain how they interact to make the CPU function.
    13·1 answer
  • People who enjoy working with their hands might enjoy a career as a/an
    9·1 answer
  • Explain mechanical computer ,electromechanical and electronic computer with example<br>​
    11·1 answer
  • What is the difference between an activity inventory and an object inventory?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!