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
noname [10]
3 years ago
15

Write the reverseO function recursively. This function takes a string and the length of the string as arguments and returns the

same string with its characters in the reverse order
Computers and Technology
2 answers:
Rudiy273 years ago
4 0

Answer:

// here is code in java.

// import package

import java.util.*;

// class definition

class Main

{

// method that return reverse string

   public static String reverseO(String st,int n)

   {

   // create an empty string

       String rev_st="";

       for(int x=n-1;x>=0;x--)

       {

       // append character from last into the empty string

           rev_st=rev_st+st.charAt(x);

       }

       // return the reversed string

       return rev_st;

   }

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

       // scanner object to read string

Scanner scr=new Scanner(System.in);

System.out.print("enter the string:");

 // read the string from user

   String st=scr.nextLine();

   // find the length of string

   int len=st.length();

   // call the method with parameter string and length

   System.out.println("reverse string is: "+reverseO(st,len));

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a string from user and assign it to variable "st" and Find  its length. Then call the method reverseO() with parameter string and length.Then in the method reverseO(), create an empty string.Then append the characters of input string to empty string from last index.Then return the string.This will be the string in reverse order.

Output:

enter the string:hello

reverse string is: olleh

katen-ka-za [31]3 years ago
3 0

Answer:

See the other answer for the solution in Java. However, to make the reversing truly recursive, replace it by this:

 public static String reverseO(String st,int n)

  {

   String ret = st.substring(n-1,n);

   if (n > 1)  

     ret += reverseO(st, n-1);

   return ret;

 }

Explanation:

A recursive function calls itself. The function places the last character at the start and then calls itself to do the same on the remainder of the string. Make sure there always is a stop criterium, to end the recursion.

Recursive functions are often elegant, but most of the times not very efficient in terms of stack usage.

You might be interested in
I give brainliest.
dezoksy [38]

Answer:

D.

Explanation:

Code won’t <em>usually</em> recognize statements like humans do, code has to be consistent unlike human speech.

6 0
3 years ago
The inflationary gap occurs when you obtain no increase in output, but only an increase in the Average Price Level from an incre
lina2011 [118]
<span>C. Third phase of the Keynesian LRAS Curve.</span>
3 0
3 years ago
Read 2 more answers
What is difference between local method invocation and remote method invocation?
Vlad [161]

Answer:

 Local method invocation parameters are passed by reference with the same object. Local innovation having the source code on the form of class and it basically try to invoke various methods by importing in the form of packages.

On the other hand, in remote methods invocation the parameters are passed by the copy when the given parameters are not object class. It basically allow an object that existed in another address capacity. This methods works on the client side transport.

8 0
3 years ago
Use a _____ to safeguard computer systems from voltage fluctuations.
liq [111]

Answer.

1.Surge protection board

2.Uninterrupted Power Supply (UPS)


Explanation

A surge protection board is designed to protect equipment against a power surge or over voltage in power supply.A UPS provides back up power in occasions of power outage.In most events of power cut,UPS units only allow a person to save the work and perform a controlled shutting down of a computer.

4 0
4 years ago
I need help ASAP please and thank you!
S_A_V [24]

Answer:

Explanation: For the best approach, It would say Option 3, you're supporting the waiter and making the rude customer feel as if they got what they wanted of complaining to the manager.

The worst approach I think would be Option 4, but this feels opinion based. Choose what you feel would be the best approach for this one.

6 0
3 years ago
Other questions:
  • What is the rationale behind the development of an operating system in computing?
    15·1 answer
  • Which is an example of an active visual interface? a display indicating the amount of ammunition for the currently equipped weap
    13·2 answers
  • Susan's monthly goal to open five new customer
    10·1 answer
  • Memes are life dont delete if u do then u know im right
    12·2 answers
  • You download a game from the Internet since it looks fun to play. As you begin to play the game, your computer begins
    12·1 answer
  • What is typescript can you please give me a description of what it is
    13·1 answer
  • A soft news story and a feature story are the same thing.<br> O True<br> O False<br> HELLPP ASSAAAP
    12·2 answers
  • How tractors are controlled
    8·2 answers
  • Education leads to higher wages lower unemployment.* True or false
    5·1 answer
  • Which very high-speed fiber network was already in place and being used for wide area networking (wan) transmissions, before the
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!