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 3 of 3

Thread: Reverse character using void method

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Reverse character using void method

    I need help to write a parameterless, void and recursive method used to reverse a string of character. Can anybody help me with the last part?
    This is the code I been able to write so far :


    import java.util.*;
    public class Labex78
    {
        public static String put = put;
        static boolean check= true;
                   public static void main(String[] args)
    	       {
     
                    reverse();
                   }   
                  public static void reverse()			
                    {
                     Scanner kbd= new Scanner(System.in);
                     if(check==true){
                     System.out.println("Enter 5 characters");
                       put = kbd.nextLine();
                      check= false;}
     
                     int len = put.length();
                       if(len<=1)
                       {
                         System.out.print(put);
                       }
                       else
                       {
                        String rev ="";
                        rev += put.charAt(put.length()-1); 
                        put= put.substring(0,put.length()-1);
                        reverse();
                        System.out.println(" Read backwards, character becomes "+ rev);
                       }
                  }
     }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Reverse character using void method

    What is the problem?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reverse character using void method

    doesn't work . that ELSE part is not reversing the string. and I was wondering how I can use a void , parameterless function that is also recursive without keeping ro prompt the user to enter a string of characters. Basically how do use a string input by a user in such function??

Similar Threads

  1. Replies: 1
    Last Post: February 4th, 2010, 04:23 PM
  2. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM
  3. Calling a void method into a static void main within same class
    By sketch_flygirl in forum Object Oriented Programming
    Replies: 3
    Last Post: November 15th, 2009, 05:24 PM
  4. Reverse Number
    By java1 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 28th, 2009, 10:19 AM
  5. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM