Shuffle two Strings recursively to make another StringWhat is the difference between String and string in C#?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?Why is subtracting these two times (in 1927) giving a strange result?Why is char[] preferred over String for passwords?

What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

What is the PIE reconstruction for word-initial alpha with rough breathing?

Anagram holiday

prove that the matrix A is diagonalizable

Etiquette around loan refinance - decision is going to cost first broker a lot of money

How can saying a song's name be a copyright violation?

Why is Collection not simply treated as Collection<?>

Blender 2.8 I can't see vertices, edges or faces in edit mode

Neighboring nodes in the network

Fully-Firstable Anagram Sets

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

Took a trip to a parallel universe, need help deciphering

Arrow those variables!

Did Shadowfax go to Valinor?

SSH "lag" in LAN on some machines, mixed distros

What do you call someone who asks many questions?

A reference to a well-known characterization of scattered compact spaces

Facing a paradox: Earnshaw's theorem in one dimension

In a Spin are Both Wings Stalled?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How much of data wrangling is a data scientist's job?

I'm flying to France today and my passport expires in less than 2 months



Shuffle two Strings recursively to make another String


What is the difference between String and string in C#?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?Why is subtracting these two times (in 1927) giving a strange result?Why is char[] preferred over String for passwords?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I'm trying to create a method shuffle (String stri, String str2, String str3) that returns a boolean and take two Strings and "shuffles" them to make a third String, but I'm trying to do it recursively, which is kind of tough for me to think about. I want to return true if str1 and str2can be shuffled and return false if they can't be shuffled.



For example, if str1 = "tv" and str2 = "aol", the method might return taovl.



I also plan to test the method out as well as create another helper method to make it more efficient, but that's easy.










share|improve this question






















  • What have you tried? What specifically do you kneed help with?

    – Carcigenicate
    Mar 2 at 21:29






  • 1





    How do you define if a String can be "shuffled"?

    – GBlodgett
    Mar 2 at 21:31











  • I need help finding the base cases, but also need help with calling the recursive method.

    – MontyLemons
    Mar 2 at 21:39






  • 1





    Passing the third String to your method will not work. You need your method to RETURN the generated String.

    – FredK
    Mar 2 at 21:43











  • Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

    – FredK
    Mar 2 at 21:46

















-1















I'm trying to create a method shuffle (String stri, String str2, String str3) that returns a boolean and take two Strings and "shuffles" them to make a third String, but I'm trying to do it recursively, which is kind of tough for me to think about. I want to return true if str1 and str2can be shuffled and return false if they can't be shuffled.



For example, if str1 = "tv" and str2 = "aol", the method might return taovl.



I also plan to test the method out as well as create another helper method to make it more efficient, but that's easy.










share|improve this question






















  • What have you tried? What specifically do you kneed help with?

    – Carcigenicate
    Mar 2 at 21:29






  • 1





    How do you define if a String can be "shuffled"?

    – GBlodgett
    Mar 2 at 21:31











  • I need help finding the base cases, but also need help with calling the recursive method.

    – MontyLemons
    Mar 2 at 21:39






  • 1





    Passing the third String to your method will not work. You need your method to RETURN the generated String.

    – FredK
    Mar 2 at 21:43











  • Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

    – FredK
    Mar 2 at 21:46













-1












-1








-1


0






I'm trying to create a method shuffle (String stri, String str2, String str3) that returns a boolean and take two Strings and "shuffles" them to make a third String, but I'm trying to do it recursively, which is kind of tough for me to think about. I want to return true if str1 and str2can be shuffled and return false if they can't be shuffled.



For example, if str1 = "tv" and str2 = "aol", the method might return taovl.



I also plan to test the method out as well as create another helper method to make it more efficient, but that's easy.










share|improve this question














I'm trying to create a method shuffle (String stri, String str2, String str3) that returns a boolean and take two Strings and "shuffles" them to make a third String, but I'm trying to do it recursively, which is kind of tough for me to think about. I want to return true if str1 and str2can be shuffled and return false if they can't be shuffled.



For example, if str1 = "tv" and str2 = "aol", the method might return taovl.



I also plan to test the method out as well as create another helper method to make it more efficient, but that's easy.







java string recursion static boolean






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 2 at 21:28









MontyLemonsMontyLemons

13




13












  • What have you tried? What specifically do you kneed help with?

    – Carcigenicate
    Mar 2 at 21:29






  • 1





    How do you define if a String can be "shuffled"?

    – GBlodgett
    Mar 2 at 21:31











  • I need help finding the base cases, but also need help with calling the recursive method.

    – MontyLemons
    Mar 2 at 21:39






  • 1





    Passing the third String to your method will not work. You need your method to RETURN the generated String.

    – FredK
    Mar 2 at 21:43











  • Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

    – FredK
    Mar 2 at 21:46

















  • What have you tried? What specifically do you kneed help with?

    – Carcigenicate
    Mar 2 at 21:29






  • 1





    How do you define if a String can be "shuffled"?

    – GBlodgett
    Mar 2 at 21:31











  • I need help finding the base cases, but also need help with calling the recursive method.

    – MontyLemons
    Mar 2 at 21:39






  • 1





    Passing the third String to your method will not work. You need your method to RETURN the generated String.

    – FredK
    Mar 2 at 21:43











  • Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

    – FredK
    Mar 2 at 21:46
















What have you tried? What specifically do you kneed help with?

– Carcigenicate
Mar 2 at 21:29





What have you tried? What specifically do you kneed help with?

– Carcigenicate
Mar 2 at 21:29




1




1





How do you define if a String can be "shuffled"?

– GBlodgett
Mar 2 at 21:31





How do you define if a String can be "shuffled"?

– GBlodgett
Mar 2 at 21:31













I need help finding the base cases, but also need help with calling the recursive method.

– MontyLemons
Mar 2 at 21:39





I need help finding the base cases, but also need help with calling the recursive method.

– MontyLemons
Mar 2 at 21:39




1




1





Passing the third String to your method will not work. You need your method to RETURN the generated String.

– FredK
Mar 2 at 21:43





Passing the third String to your method will not work. You need your method to RETURN the generated String.

– FredK
Mar 2 at 21:43













Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

– FredK
Mar 2 at 21:46





Seems like a simple single loop will do this. I can't imagine how recursion would be at all desirable.

– FredK
Mar 2 at 21:46












2 Answers
2






active

oldest

votes


















0














import java.util.Scanner;
public class lab3
public static void main(String[] args)
String str;
System.out.print("Enter String: ");
Scanner sc = new Scanner(System.in);
str = sc.nextLine();
String res = revRec3(str);
System.out.println(res);


public static String revRec3(String str)

if (str.length() <= 1)
return str;
else
String first = str.substring(0, str.length() / 3);
String second = str.substring(str.length() / 3, ((2 * str.length()) / 3));
String third = str.substring((2 * str.length()) / 3, str.length());

return revRec3(third)+revRec3(second)+revRec3(first);





try doing something like this. This Program splits a String into 3 pieces and then reverses them using recursion.






share|improve this answer






























    0














    I solved this by simply creating three integer variables to go through the indices of all three strings and checking to see if a a letter at any index matches the same order of s3






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54963193%2fshuffle-two-strings-recursively-to-make-another-string%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      import java.util.Scanner;
      public class lab3
      public static void main(String[] args)
      String str;
      System.out.print("Enter String: ");
      Scanner sc = new Scanner(System.in);
      str = sc.nextLine();
      String res = revRec3(str);
      System.out.println(res);


      public static String revRec3(String str)

      if (str.length() <= 1)
      return str;
      else
      String first = str.substring(0, str.length() / 3);
      String second = str.substring(str.length() / 3, ((2 * str.length()) / 3));
      String third = str.substring((2 * str.length()) / 3, str.length());

      return revRec3(third)+revRec3(second)+revRec3(first);





      try doing something like this. This Program splits a String into 3 pieces and then reverses them using recursion.






      share|improve this answer



























        0














        import java.util.Scanner;
        public class lab3
        public static void main(String[] args)
        String str;
        System.out.print("Enter String: ");
        Scanner sc = new Scanner(System.in);
        str = sc.nextLine();
        String res = revRec3(str);
        System.out.println(res);


        public static String revRec3(String str)

        if (str.length() <= 1)
        return str;
        else
        String first = str.substring(0, str.length() / 3);
        String second = str.substring(str.length() / 3, ((2 * str.length()) / 3));
        String third = str.substring((2 * str.length()) / 3, str.length());

        return revRec3(third)+revRec3(second)+revRec3(first);





        try doing something like this. This Program splits a String into 3 pieces and then reverses them using recursion.






        share|improve this answer

























          0












          0








          0







          import java.util.Scanner;
          public class lab3
          public static void main(String[] args)
          String str;
          System.out.print("Enter String: ");
          Scanner sc = new Scanner(System.in);
          str = sc.nextLine();
          String res = revRec3(str);
          System.out.println(res);


          public static String revRec3(String str)

          if (str.length() <= 1)
          return str;
          else
          String first = str.substring(0, str.length() / 3);
          String second = str.substring(str.length() / 3, ((2 * str.length()) / 3));
          String third = str.substring((2 * str.length()) / 3, str.length());

          return revRec3(third)+revRec3(second)+revRec3(first);





          try doing something like this. This Program splits a String into 3 pieces and then reverses them using recursion.






          share|improve this answer













          import java.util.Scanner;
          public class lab3
          public static void main(String[] args)
          String str;
          System.out.print("Enter String: ");
          Scanner sc = new Scanner(System.in);
          str = sc.nextLine();
          String res = revRec3(str);
          System.out.println(res);


          public static String revRec3(String str)

          if (str.length() <= 1)
          return str;
          else
          String first = str.substring(0, str.length() / 3);
          String second = str.substring(str.length() / 3, ((2 * str.length()) / 3));
          String third = str.substring((2 * str.length()) / 3, str.length());

          return revRec3(third)+revRec3(second)+revRec3(first);





          try doing something like this. This Program splits a String into 3 pieces and then reverses them using recursion.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 2 at 21:53









          Kyle LynchKyle Lynch

          14




          14























              0














              I solved this by simply creating three integer variables to go through the indices of all three strings and checking to see if a a letter at any index matches the same order of s3






              share|improve this answer



























                0














                I solved this by simply creating three integer variables to go through the indices of all three strings and checking to see if a a letter at any index matches the same order of s3






                share|improve this answer

























                  0












                  0








                  0







                  I solved this by simply creating three integer variables to go through the indices of all three strings and checking to see if a a letter at any index matches the same order of s3






                  share|improve this answer













                  I solved this by simply creating three integer variables to go through the indices of all three strings and checking to see if a a letter at any index matches the same order of s3







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 21 at 21:57









                  MontyLemonsMontyLemons

                  13




                  13



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54963193%2fshuffle-two-strings-recursively-to-make-another-string%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript