• Post Reply Bookmark Topic Watch Topic
  • New Topic

BlueJ Help  RSS feed

 
Hansjürgen Peter
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm new here and i need help about BlueJ and Java programming.
How i can make Switch-Case statemant in BlueJ? And for what i need this Switch-Case statement?
I have read a bit about it and I do not understand it.
You have for the Swicht-Case statement several cases, but will run the Switch-Case statement all of this cases or only one of this cases.

Thank you.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I don't like BlueJ myself, and prefer to use the command line. But there is no difference between how BlueJ handles a switch statement and how anything else handles a switch statement. Have you read the Java™ Tutorials about switch statements?

A switch is often useful when you have a lot of if statements like this:-You can write that asThat can be executed very quickly because the compiler sets up a lookup table in the bytecode. But the values after case must be ints (or some other sorts of integer) enum elements or (after Java7) Strings. Also the value of whatever follows case must be known to the compiler.
As you will see from the tutorials link I gave you, whether you execute one line or several lines depends on where you write break.
 
Conor Graham
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another topic you may like to look into, is also the use of Enums. The only reason I mention this is because a lot of the time, they can be used alongside switch statement, for example, days of the week etc.
Enum Information

 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch CG
 
Conor Graham
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sheriff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!