• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

method that reads a string for vowels?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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-
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Mike Pirrone
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String.charAt with a switch would be perfect. Just put it in a for loop and that should fly.
 
Mike Pirrone
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you i really appreciate it. ill keep you updated on my progress.
-mike-
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Pirrone
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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-
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic