• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

program errors(switch statement)

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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*
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic