File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Switch or Else If Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Switch or Else If" Watch "Switch or Else If" New topic

Switch or Else If

Imogen Handy

Joined: May 03, 2013
Posts: 1
My project requires me to create a game which produces random and golden ratio rectangles when the user presses one button, i have attempted to use a swich statement here so when the user clicks the programme will either draw a rectangle or a golden ratio rectange but when the button is clicked it only draws the 1st case is there anyway to get it to alternate between cases? Or should i be using an if else statement or even something else

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33111

Welcome to CodeRanch! We used "code" instead of "highlight" here for blocks of code. I've edited your post to fix that so the code is easier to read.

I would use the if/else there since there are only two cases. It is a little clearer that way.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Switch or Else If
It's not a secret anymore!