File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes method that reads a string for vowels? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method that reads a string for vowels?" Watch "method that reads a string for vowels?" New topic
Author

method that reads a string for vowels?

Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
I am to create a program that asks the user to enter a string in any combination. Once the string is entered the number of each vowel in the string is outputed as well as the remaining nonvowel characters (including spaces). I pseudocoded and planned out how I am going to do the program. My only question though, how do I compare the string to my case structure that will have a separate counter for each vowel and the remaining characters. Is there a method in Java I can use? Thanks so much.
-mike-
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I'm not sure I'm getting what you mean.
Do you mean, how do I extract each character in the String to compare to the individual vowels? If so, you can use the String.charAt(int). If not, can you explain in a little more detail what you are asking for?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
my apologies. This is for my OOP class at UNF in jax, fl.
the program asks the user to enter a string . for example, lets say i enter "Hello World". The program would out put there are 0 A's, 1 E, 0 I's, 2 O's, 0 U's, and 8 other characters (including spaces). does that help ? thanks
-mike
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
String.charAt with a switch would be perfect. Just put it in a for loop and that should fly.
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
thank you i really appreciate it. ill keep you updated on my progress.
-mike-
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
IF you're using jdk 1.4, it's as easy as


ps - this is of the top of my head, so case/spelling may be off, but it's the general idea.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Java Regular Expressions
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
i wish i could do it that easily but our professor is requiring us to use a switch statement and a while statement. thats an awesome way to do it though. i wish i could.
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
i have everything up and running smoothly but just one problem. for my user output it will output how many of each vowel/characters there are after each individual character.
for example if i enter "AEIOU" I will get
1 A 0 E 0 I 0 O 0 U 0 other characters
0 A 1 E 0 I 0 O 0 U 0 other characters
0 A 0 E 1 I 0 O 0 U 0 other characters
0 A 0 E 0 I 1 O 0 U 0 other characters
0 A 0 E 0 I 0 O 1 U 0 other characters
I want the output to occur for the entire string on one line. here is my code for the for loop with the switch.

im not asking for anyone to code for me, just wanting to know where I am going wrong. My first guess was that as the variable i was incremented in the for loop it printed out the statments each time it was incremented in the loop. So I tried putting the statements outside the for loop but when I did that, it said it did not regonize the counters. thanks for any help
-mike-
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
ok i figured it out! wow, you dive into something and you don't want to stop. I started this thing about 4 hours ago and finally figured everything out and the program is up and running perfect. thank you so much for helping me out javaranch! i greatly appreciate it.
-mike-
 
 
subject: method that reads a string for vowels?