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
Which of the following would be considered a strong password?
ikadub [295]

A, because it is full of random symbols and numbers,

3 0
3 years ago
Read 2 more answers
EBay buyers voluntarily comment to other users and sellers on the quality of service, promptness of shipping, and their general
Orlov [11]

Answer:

I picked c

Explanation:

3 0
3 years ago
List one unprofessional AND one professional example of internet/social media
Leni [432]

Professional: Using social media to advertise a company you created

Unprofessional: Using social media to watch cat videos

4 0
3 years ago
In black and white,<br><br> we must be more conscious of image
scZoUnD [109]

is it true or false is so it is false

3 0
3 years ago
Help please!! worth 10 pts! answer quick please!
WINSTONCH [101]

Answer:

it has helped the people of today by

1.helped the young generation with there homework

2.you can book an hotel through the internet

3.you can also book a plane ticket via the internet

4.it is easier to look to ur email message via the internet

4 0
3 years ago
Other questions:
  • Margins can be modified in the page layout or by using__.
    15·1 answer
  • Given 3 floating-point numbers. Use a string formatting expression with conversion specifiers to output their average and their
    14·1 answer
  • Select the correct navigational path to mark all teachers who have achieved “excellent” on their evaluations a red background.
    11·2 answers
  • Which of the following illustrations is depicted in the icon that's used to access Windows Help and Support files?
    13·1 answer
  • The auxiliary device used to store large volume of data and program for future is called​
    10·1 answer
  • Que relacion tiene Las palabras: fermentacion-vino y clonacion- dolly​
    9·1 answer
  • You have two identical print devices that are set up in a work room. Currently, the Windows print server has two printers config
    13·1 answer
  • Which iteration must have an expression that has a true or false value?
    10·1 answer
  • Give an example of what Artificial Intelligence application most popular is used on a daily basis.
    12·2 answers
  • What do hard disk drive use to store data
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!