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
What is the best definition of the 7x7 rule for maximizing audience comprehension
olganol [36]

The 7x7 Rule states that a PowerPoint slide should have no more than seven lines of text and no more than seven words in each of those lines.

7 0
3 years ago
The net force on a vehicle that is accelerating at a rate of 1.2 m/s2 is 1500 newtons. What is the mass of the vehicle to the ne
Rudiy27

Answer:

The mass of the vehicle is 1250kg

Explanation:

Given

Net\ Force = 1500N

Acceleration = 1.2m/s^2

Required

Determine the vehicle's mass

This question will be answered using Newton's second law which implies that:

Net\ Force (F) =  Mass (m) * Acceleration (a)

In other words:

F = ma

Substitute values for F and a

1500 = m * 1.2

Make m the subject

m = \frac{1500}{1.2}

m = 1250kg

<em>Hence, the mass of the vehicle is 1250kg</em>

6 0
3 years ago
When using Identify from the IPDE cycle, you are trying to _____.
Thepotemich [5.8K]

B) observe hazards in your environment.

8 0
3 years ago
Read 2 more answers
How to set up a simple peer-to-peer network using a star topology?
kkurt [141]

Answer:

The description including its scenario is listed throughout the explanation section below.

Explanation:

Star topology seems to be a LAN system under which all points are connected to a single cable link location, such as with a switch as well as a hub. Put it another way, Star topology is among the most commonly used network configurations.

Throughout this configuration or setup:

  • Each common network setups network unit, such as a firewall, switch, as well as computer.
  • The main network computer serves as either a server as well as the peripheral system serves as just a client.
7 0
3 years ago
What form of infrastructure improved trade and communication among Roman cities?
grigory [225]

Answer:

aqueducts

Explanation:

5 0
3 years ago
Other questions:
  • Describe a situation where it would be appropriate to use each of the six leadership styles described by Daniel Goleman
    7·1 answer
  • Section: Friction
    10·1 answer
  • Which is an example of Raw Input?
    11·1 answer
  • Marilyn needs help exporting her spreadsheet as a few different types of files. She needs to know exactly how her file should be
    11·1 answer
  • Using your computer for non-work activities while you are being paid to work is known as ________. Select one: A. cyber sleeping
    13·2 answers
  • Weak Induction
    8·1 answer
  • What is the best way to get the most out of the box?
    14·2 answers
  • Type of operating system used i handleheld device
    6·1 answer
  • Why entity relationship model is used for data manipulation??<br><br>​
    15·1 answer
  • Difference between customized and packaged software​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!