This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Switch statement: Illegal start of expression (huh?!)

 
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone fix this code for me?



Thanks.
 
Saloon Keeper
Posts: 2658
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably mean default: not case default:

The Java™ Tutorials - The switch Statement
 
Rancher
Posts: 3303
27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thomas Mahoney wrote:


You've commented out the closing brace here.
 
Bartender
Posts: 708
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that there is no need for curly braces inside each case-block. So:
Also noted that I include a "break" statement in the defauot clause. The reason for this is that it is not required for the default clause to come after all of the case clauses (but it is usually considered good practice to do so).
 
Ranch Hand
Posts: 38
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.

change to


2.

change to


example:

en.verejava.com/?id=20047960488848
 
Marshal
Posts: 65057
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does line 37 mean? I think it will cause you trouble.
 
joseph hu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please delete



may be dead loop.
 
Thomas Mahoney
Greenhorn
Posts: 12
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys.  I fixed it, and you helped a lot.  Oh, and line 37 is the tail end of a Do While loop meant to repeat this entire switch statement while the enclosed variable's value is greater than 0, only I didn't include the entire loop statement.

Thanks Again.
 
Sheriff
Posts: 6110
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great job!  Would you mind posting your final code so that others can benefit from it?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while (choice >= 1); why this condition??
 
Knute Snortum
Sheriff
Posts: 6110
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thomas Mahoney wrote:...  Oh, and line 37 is the tail end of a Do While loop meant to repeat this entire switch statement while the enclosed variable's value is greater than 0, only I didn't include the entire loop statement....

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!