Question

write a java program :- Use a recursive method that can take an arbitrarily long string...

write a java program :-

Use a recursive method that can take an arbitrarily long string and reverse the order of its characters. Example: "Real men don't eat quiche." would be ".ehciuq tea t'nod nem leaR"

must use RECURSION to solve this challenge.

make sure to comment the code thoroughly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
    
public class CountingMethods {

    public static void main(String[] args) {
        
        System.out.println(reverseMe("Real men don't eat quiche."));
        
    }
    
    public static String reverseMe(String s) {
        if(s.length() <= 1) {
            return s;
        }
        return s.charAt(s.length()-1) + reverseMe(s.substring(1, s.length()-1)) + s.charAt(0);
    }

}










sterminated> CountingMethods Dava Applicatio .ehciuq tae tnod nem laeR 29 0 public static String reverseMe (String s) 31 32


Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

sterminated> CountingMethods Dava Applicatio .ehciuq tae t'nod nem laeR 29 0 public static String reverseMe (String s) 31 32 if(s.length) 1)f return s return s.charAt(s.length)-1) reverseMe(s.substring(1, s.length)-1))s.charAt (0); 35 36 37 38 39 40 41 42 43

Add a comment
Know the answer?
Add Answer to:
write a java program :- Use a recursive method that can take an arbitrarily long string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of...

    MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of all occurrences of a given word in all the files under a directory. Write a test program. Use the following header: public static long findInFile(File file, String word)

  • Java Program Write a recursive method that takes a string and return a string where every...

    Java Program Write a recursive method that takes a string and return a string where every character appears twice. Output must match exactly as below: only two LL's since there is already two of the character For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it. must be recursive!!!

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • [10 marks] Write a recursive method, reverse, that displays a string in a reverse order. For...

    [10 marks] Write a recursive method, reverse, that displays a string in a reverse order. For example, reverse("UBC-O") displays O-CBU. Use a helper method to improve the performance of your program. Write a test program that prompts the user to enter a string and displays its reversal. MUST HAVE A HELPER METHOD TO IMPROVE PERFORMANCE. FOR JAVA THANK YOU!

  • In java, write a program with a recursive method which asks the user for a text...

    In java, write a program with a recursive method which asks the user for a text file (verifying that the text file exists and is readable) and opens the file and for each word in the file determines if the word only contains characters and determines if the word is alpha opposite. Now what I mean by alpha opposite is that each letter is the word is opposite from the other letter in the alphabet. For example take the word...

  • Using Java only Implement a program that uses a recursive method to print a string backward....

    Using Java only Implement a program that uses a recursive method to print a string backward. Your program must contain a recursive method that prints the string backward. Use appropriate parameters in your method.

  • JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string...

    JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string of someone's full name and prints it out last name first. You may use the available string manipulation methods. Example: "George Washington" "Washington, George" 2. Write a program that will take a string of someone's full name, and break it into separate strings of first name and last name, as well as capitalize the first letter of each. Example: "joseph smith", "Joseph" "Smith"

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • Please use Java. Write a non-recursive method that uses a stack to check whether its string...

    Please use Java. Write a non-recursive method that uses a stack to check whether its string parameter is a palindrome. Write a program to test and demo your method. Fibonacci Numbers Write a method that uses a stack to determine the desired Fibonacci number. Write a program to test and demo your method. Balancing Grouping Symbols Write a method that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ), curly...

  • Write a java program that demonstrates recursion. This program can be in a java GUI frame...

    Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.) The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line. Demonstrate recursion with a function called LoadTruck() that takes a number of boxes...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT