• Post Reply Bookmark Topic Watch Topic
  • New Topic

the switch and String combo  RSS feed

 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i understand the jave version 1.7 can accept strings in the switch statements. but i did something like found below and netbeans tells me, "cannot find symbol varable y":



what am i doing wrong?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37489
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because y is a variable (that doesn't exist) and "y" is a string.

Try case "y":
 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:That's because y is a variable (that doesn't exist) and "y" is a string.

Try case "y":

that worked . thanks.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In older versions of Java, all cases had to be followed by a compile‑time constant. That bit hasn't changed.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!