Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3870518
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:44:07+00:00 2026-05-19T21:44:07+00:00

I have a recursive method that reversed a string (HW assignment, has to be

  • 0

I have a recursive method that reversed a string (HW assignment, has to be recursive). I did it….but its only returning the value of the string after the first pass. By analyzing the output after each pass i can see it does do its job correctly. heres my code, and the output i get below it:

    String s = "Hello, I love you wont you tell me your name?";
int k=0;
public String reverseThisString(String s) {
    if(k!=s.length()) {
        String first =s.substring(0,k)+s.charAt(s.length()-1);
        String end = ""+s.substring(k, s.length()-1);
        k++;
        s=first+end;
        System.out.println(s);
        this.reverseThisString(s);
    }
    return s;
}

output:

?Hello, I love you wont you tell me your name
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:44:08+00:00Added an answer on May 19, 2026 at 9:44 pm

    I think you need to change this:

    this.reverseThisString(s);
    

    to this:

    return this.reverseThisString(s);
    

    otherwise the result of the method call is simply discarded.

    I would also recommed that you change k to be a parameter to the method rather than a member.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a recursive method that returns categories, and checks for its sub categories.
I have a problem with a recursive method that fills a structure LinkedHashMap<String,LinkedHashMap<String, Integer>>
Often, I have a recursive routine within a method that is only called by
I have a recursive method on the base form that takes in a control
Welcome! I have a recursive public static method named less that takes a tree
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
I have the following method that works well, except the yield break statement only
I have a recursive call to a method that throws a stack overflow exception.
I have a recursive method that allocates an NSMutableArray, runs a recursive call and
I have a recursive variadic templated method that is called from a non-recursive variadic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.