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
Assume the existence of a Building class with a constructor that accepts two parameters:_________ a reference to an Address obje
Maksim231197 [3]

Answer:

class Building { int toatalUnit; Building(Building add, int x) { } } public class ApartmentBuilding extends Building { int toatalUnit; ApartmentBuilding(ApartmentBuilding add, int a, int b) { super(add, b); this.toatalUnit = b; } }

Explanation:

Assume the existence of a Building class with a constructor that accepts two parameters:_________ a reference to an Address object representing the building's address, and an integer for the square footage of the building. Assume a subclass ApartmentBuilding has been defined with a single integer instance variable, totalUnits. Write a constructor for ApartmentBuilding that accepts three parameters: an Address and an integer to be passed up to the Building constructor, and an integer used to initialize the totalUnits instance variable.

class Building { int toatalUnit; Building(Building add, int x) { } } public class ApartmentBuilding extends Building { int toatalUnit; ApartmentBuilding(ApartmentBuilding add, int a, int b) { super(add, b); this.toatalUnit = b; } }

5 0
3 years ago
Ben is writing web page content on a newly launched gaming gadget. He has to use hyperlinks to help visitors navigate to web pag
iren2701 [21]

Answer:

at the bottom of the web page

Explanation:

Ben is creating a web page content for the gaming gadget that  has been newly launched. He uses hyperlinks so that the visitors can navigate the web pages properly which deals with some other electronic gadgets also. So Ben should place the hyperlinks at the bottom of the web page as it will provide anyone viewing the web pages easily.

3 0
3 years ago
PUBG mobile id and name plz
ycow [4]
KSK Jemens je Jemen jeme this is mine
5 0
3 years ago
Sam would like to install a new application on every computer in his SOHO network. All the computers are currently connected in
lisabon 2012 [21]

Let us assume that Sam has an Active Directory Domain in his SOHO network.  He can use features that come with an AD domain to deploy software packages via Group Policy Objects. These features from Microsoft not only give us simple ways to deploy software, but also provide solutions to uninstall too. Another option to consider using is through 3rd party software solutions like PDQ Deploy. This tool will help deploy any Windows application to multiple PCs in the same workgroup.

4 0
4 years ago
What will help the programmer understand what’s going on in the program?
Over [174]

Answer:

Programming languages to help solve algorithms

Explanation:

6 0
3 years ago
Other questions:
  • Ian recently earned his security certification and has been offered a promotion to a position that requires him to analyze and d
    6·1 answer
  • Which of the following is NOT a safety practice for working near power lines?
    14·1 answer
  • Which of these is not part of the art director's job?
    9·2 answers
  • How many lines of text are in your questionnaire document
    5·1 answer
  • Star and peer-to-peer are types of
    9·2 answers
  • Can anyone help explain this?
    13·2 answers
  • Pleasee telllllllllllllllllll​
    15·1 answer
  • Match the following internet related terms to their definition
    13·1 answer
  • Where is the fill handle located
    7·1 answer
  • Write a simple program that takes in a numerator and denominator and then computes the GCD for that fraction. You can assume tha
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!