Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: String Reverser Program

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default String Reverser Program

    I was tasked to make a program that took a string input, then reversed it using recursion. I'm getting a syntax error causing an exit code 1. Also, I'm sure there may be an error in the code as I'm not very strong with recursion. Any help with this (specifically this obnoxious syntax error which I can't seem to find) would be very helpful!

    import java.util.Scanner;
     
    public class StringReverser
    {
    	public static void main(String[] args)
    	{
    		String input;
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("Please enter a string to be reversed: ");
    		input = keyboard.nextLine;
     
    		reverse(input);
    	}
     
    	public static String reverse(String str)
    	{
    		if((null == str) || (str.length() <= 1))
    		{
    			return str;
    		}
     
    		return reverse(str.substring(1)) + str.charAt(0);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: String Reverser Program

    syntax error which I can't seem to find
    What compiler are you using? The javac compiler gives very nice error messages.
    Please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: String Reverser Program

    I actually managed to find the problem is there a way to delete a post?

  4. #4
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: String Reverser Program

    Just mark it as solved.

Similar Threads

  1. Issue with Caeser Shift, Transpose, and Reverser
    By biwot in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2014, 06:31 AM
  2. Replies: 1
    Last Post: February 6th, 2014, 01:11 PM
  3. Help with String based program!!!
    By astroann in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 27th, 2010, 10:07 PM
  4. Help with String based program!!!
    By astroann in forum Member Introductions
    Replies: 3
    Last Post: December 27th, 2010, 10:07 PM
  5. Replies: 5
    Last Post: January 30th, 2009, 09:31 PM