Results 1 to 7 of 7
  1. #1
    Java01 is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default Recursion in Java ..

    need help on recursion, i don't know how to add a character into a string. for example:

    adding 'a' into position 5 for example.. into the string "bcdefg" so it would go after f.. I know you can use CharAt but all i need is a start, im having trouble starting the code

    any help?

  2. #2
    Java01 is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    any help? i got to have it working within 20 mins!

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    Java01 is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    i havn't done much, i need help starting it off, i have a few notes here and there.. like :

    public String rev3 (String str1, String str2, int num) {
    if ((str1.length()) == 0) return str2;

    im just really stuck lol, if you can help start me off i can get it hopefully!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    This is not related with recursion. I don't know from where you came with that word.

    Here is a simple way to do it.

    Java Code:
            String str = "bcdefg";
            str = str.substring(0, 4) + "a" + str.substring(4);
            System.out.println(str);

  6. #6
    Java01 is offline Member
    Join Date
    Oct 2008
    Posts
    6
    Rep Power
    0

    Default

    oh ok, we got taught that way in lectures, we used a method called rev3, recursion but thanks!

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. java recursion infinite loop
    By tony404 in forum Advanced Java
    Replies: 9
    Last Post: 10-03-2008, 01:16 PM
  2. help with recursion
    By Nari in forum New To Java
    Replies: 15
    Last Post: 04-24-2008, 09:13 AM
  3. i could not get the recursion in java
    By sivasayanth in forum New To Java
    Replies: 3
    Last Post: 04-23-2008, 08:08 AM
  4. Help With Recursion
    By andrew777 in forum New To Java
    Replies: 1
    Last Post: 03-29-2008, 12:51 PM
  5. Recursion in java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •