wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes program errors(switch statement) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "program errors(switch statement)" Watch "program errors(switch statement)" New topic
Author

program errors(switch statement)

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
This program is supposed to take a word which is entered by the user, and using the switch statement in the NumberOfVowels method compute the number of vowels in the word and and return that to the main method to be displayed. The problem is, I keep getting these errors that I can't seem to fix. This is exactly how my java text book does the same switch statement.
If anyone has any suggestions as to how I might fix this, I would be eternally grateful. Below is the code, and the error messages...

error:
C:\Documents and Settings\Administrator\My Documents\VowelCount.java:29: incompatible types
found : java.lang.String
required: int
int count = NumberOfVowels(input, NumChar
*the errors continue all through the other vowels in the switch statement*
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You're using double quotes around the letters, which makes them strings; the case labels have to be integers, or things that can be converted to integers, like the "char" character type. Use single quotes like

and now a is a character, not a String, and this particular error will be fixed.
Little things mean a lot!


[Jess in Action][AskingGoodQuestions]
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Aha! Thanks much. Yeah I know the little things matter, I'll leave a semicolor or a quote out and get like 15 error messages. Its nuts
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: program errors(switch statement)
 
Similar Threads
Please help me get started with this assignment
Missing method body? Eeek!
urgent help! my while loop is not working
help with counting operands and operaters
One more question, then thats it I promise :) ...