13
votes
13answers
25k views

Whats the best way to recursively reverse a string in Java?

I have been messing around with recursion today. Often a programming technique that is not used enough. I set out to recursively reverse a string. Here's what I came up with: //A method to reverse a ...
0
votes
4answers
3k views

How can I find the longest word in a string recursively?

Finished, thanks everyone. Here's the revised code. public static String longestWord(String sentence) { String longest; int i = sentence.indexOf(' '); if (i == -1) { return ...
4
votes
8answers
11k views

Reversing a String - Recursion - Java

So here is the code I found to reverse a string recursively...and I think I understand how it is working, but I just want to know if someone could provide an explanation of it? public static String ...
2
votes
4answers
5k views

Python reversing a string using recursion

I want to use recursion to reverse a string in python so it displays the characters backwards (i.e "Hello" will become "olleh"/"o l l e h". I wrote one that does it iteratively: def Reverse( s ): ...
1
vote
2answers
2k views

Using Recursion To Compare Strings To Determine Which Comes First Alphabetically Java

I am trying to write a method that uses recursion to compare the strings str1 and str2 and determine which of them comes first alphabetically (i.e., according to the ordering used for words in a ...
0
votes
4answers
3k views

How to return a string from char[] array using recursion loop.(java)

I am very bed in recursion... I need to convert a char[] array by using recursion loop only, into string. Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', ...
8
votes
4answers
684 views

Recursive function to match a string against a wildcard pattern

So I've been trying to solve this assignment whole day, just can't get it. The following function accepts 2 strings, the 2nd (not 1st) possibly containing *'s (asterisks). An * is a replacement for a ...
5
votes
5answers
1k views

Substring recursive algorithm not working

I'm a programming student in my first C++ class, and recently we were encouraged to write a simple recursive function to find the first occurrence of a substring in a given string. If found, it ...
4
votes
3answers
189 views

Mapping sub-sets of parentheses to chars

I am attempting to create a Scala method that will take one parent group of parentheses, represented as a String, and then map each subgroup of parentheses to a different letter. It should then put ...
3
votes
4answers
4k views

C++ recursive permutation algorithm for strings -> not skipping duplicates

I'm having trouble finding a simple statement to skip the duplicates for this recursive permutation code. I've looked everywhere and seem to only find examples using swap or java. From what I gather, ...
2
votes
1answer
520 views

Finding matching phrases between two pieces of text?

My objective is to find similar phrases from two pieces of text. I know that common words will be a problem. For example, and the we are the. In that case, I think a filter will be necessary. I want ...
1
vote
6answers
257 views

Check if all the letters in a string are capital recursively

I have to check if all the letters are capital letters in recursion, and i dont know why this isnt working: public static bool IsCapital(string str) { if (str.Length == 1) ...
1
vote
5answers
2k views

Counting vowels in a string using recursion

In my python class we are learning about recursion. I understand that it's when a function calls itself, however for this particular assignment I can't figure out how exactly to get my function to ...
1
vote
2answers
681 views

how to uncompress a given string in java recursively?

this is very easy using iteration but i have to do this using recursion. I tried to keep a count of how many times a char occurs in a string, the position and the rest of the string and output. ...
0
votes
1answer
180 views

The recursive method which will determine whether or not two strings match. The matching process should allow “wild cards”. A '@' and a '*'

the recursive method match(String x, String y) in the code below which will determine whether or not two strings match. The matching process should allow "wild cards". A '@' character will match with ...

1 2
15 30 50 per page