• Post Reply Bookmark Topic Watch Topic
  • New Topic

Case Problems  RSS feed

 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to use the 'switch' statements but I'm having some problems:

The case choice > 6 won't work - I don't know how to make it work. If it is possible to make it work - Please help me.
[ October 17, 2007: Message edited by: Christian Long ]
 
shweta pande
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
In switch statements,case declarations must be final values.We can only use int,char and short variables in case declarations and they must be declared as final keyword.

eg. if you put only 6 instead of choice>6,it 'll compile.


shweta
 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wont work because it resolves to boolean value which is illegal to use for a 'case'.
 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if I understood well what you just explained, 'switch statements' are quite limited, it might be better to use 'if else' in this case.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!