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;
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 str2
can 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
|
show 1 more comment
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 str2
can 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
What have you tried? What specifically do you kneed help with?
– Carcigenicate
Mar 2 at 21:29
1
How do you define if aString
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
|
show 1 more comment
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 str2
can 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
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 str2
can 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
java string recursion static boolean
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 aString
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
|
show 1 more comment
What have you tried? What specifically do you kneed help with?
– Carcigenicate
Mar 2 at 21:29
1
How do you define if aString
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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 2 at 21:53
Kyle LynchKyle Lynch
14
14
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 21 at 21:57
MontyLemonsMontyLemons
13
13
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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