• Post Reply Bookmark Topic Watch Topic
  • New Topic

Switch Case Statement Question Problem  RSS feed

 
Serkan Kilic
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I add here Invalid Size Number if it's less than 1 and more than 12?
I tried while loop but i still get the Size right after i get the "Invalid Size Number" message.

By the way, before you say it.Yes i have to use the JOptionPane for this question.

Question Instructions:

Display the message Size is XS if size is 1 or 2 or 3.
Display the message Size is XS if size is 4 or 5 or 6.
Display the message Size is XS if size is 7 or 8 or 9.
Display the message Size is XS if size is 10 or 11 or 12.

Display the message Invalid Size Number


 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't divide. Use fallthroughNote:
  • 1: If you use fallthrough always write comments that you intend the fallthrough. Otherwise people maintaining the program will assume it is a mistake.
  • 2: You cannot put break; after throw.
  • Another way to do it is with if‑elses. That may actually look more elegant.
     
    Liutauras Vilda
    Sheriff
    Posts: 4923
    334
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In addition to CR suggestions, probably think of creating a suitable separate method to define a dress size and print it to console or MessageDialog of JOptionPane. Don't cram everything into one main method. Always try to decompose your whole code into small few lines long methods and name them appropriately, so they'd reveal their actual intention.

    Code indenation also could be improved as it is not consistent. Check Java Code Conventions (<- link). It is more than 15 years old, but still being applied regularly.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!