This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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: 2566
323
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • 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
 
Ranch Foreman
Posts: 3243
19
  • 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: 703
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: 37
  • 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: 64473
225
  • 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: 37
  • 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.
 
Marshal
Posts: 5980
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • 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
Marshal
Posts: 5980
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • 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....

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!