473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Help with a recursion method

25
Hi everyone,

I'm trying to write a recursive method that removes vowels from a string. If someone can help me formulate a pseudocode to do this, that would be great.

So far my code is:
Expand|Select|Wrap|Line Numbers
  1. public static void RemoveVowels(String str)
  2.      if str.substring(0,1).compareToIgnoreCase("a" == 0)
  3.      {
  4.           str.replace("a", "");
  5.           RemoveVowels(s.substring(1));
  6.      }
  7.      else
  8.           RemoveVowels(s.substring(1));
  9.  
My reasoning is that if the character at beginning of string is not "a" then it'll execute the else statement and make the sentence one character shorter. Once it reaches an "a", it'll remove it and make the string one letter shorter.

I'm also having trouble of coming up with a way to return this new string. Should I use a return statement?

Thanks!
Apr 20 '09 #1
5 3893
dmjpro
2,476 2GB
Why do you need to use Recursive Call?
Use regular expression to replace all the vowels with empty String ;)

Expand|Select|Wrap|Line Numbers
  1. return your_string.replaceAll("[aeiou]","");
  2.  
You can also alternate the code, if you don't understand Regular Expression.

Expand|Select|Wrap|Line Numbers
  1. your_string = your_string.replaceAll("a","");
  2. your_string  = your_string.replaceAll("e","");
  3. .....
  4. ...
  5. return your_string.replaceAll("u","");
  6.  
Apr 20 '09 #2
milk242
25
Thanks for the help, but I'm learning from a book and would like to figure out this recursion method. I know it would be easier to use iterative method or even regular expression.
Apr 20 '09 #3
dmjpro
2,476 2GB
Ok that's fine...
What you want to learn ? Recursive Method?
Then take another example to learn it ..Suppose calculate the factorial or have Google with "recursive examples+java" ;)
Apr 20 '09 #4
JosAH
11,448 Expert 8TB
Split up your recursive problem:

1) if your string is empty there's nothing to remove.
2) remove vowels from the string yourString.substring(1);
3) if the first character is a vowel return the string returned by step 2)
4) otherwise return the first character plus the string returned by step 2)

kind regards,

Jos
Apr 20 '09 #5
milk242
25
Thanks JosAH,

That really helped a lot!

And thanks to everyone else!
Apr 20 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion....
9
by: Nak | last post by:
Hi there, I was wondering what the normal procedure for making a license provider require licensing was? I have just created a licensing class library and I want to make it require a license...
1
by: Stedak | last post by:
In the below class which is the a preferred method for iterating through the link list? I am told that the first method uses recursion and is less effiecient than the second method which uses a...
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
24
by: proctor | last post by:
hello, i have a small function which mimics binary counting. it runs fine as long as the input is not too long, but if i give it input longer than 8 characters it gives RuntimeError: maximum...
3
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I have a dataGridView in my win Form, and i get some information from my DataBase (sql) into a dataTable. I tried and tried and i can't display my result in the dataGridView. in...
20
by: athar.mirchi | last post by:
..plz define it.
30
by: Jeff Bigham | last post by:
So, it appears that Javascript has a recursion limit of about 1000 levels on FF, maybe less/more on other browsers. Should such deep recursion then generally be avoided in Javascript?...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.