Results 1 to 2 of 2
  1. #1
    R0bert0 is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default Newbie Question - Switch

    Hey, just wondering if anybody could help me out here.

    Little bit of example code:

    Java Code:
    private void numberGen() {
    		int x = Random.nextInt(1,30);
    		switch (x) {
    			case 10:
    				(Do some action);
    				break;
    			case 20:
    				(Do some action);
    				break;
    			case 30:
    				(Do some action);
    				break;
    		}
    	}
    What i'm looking to do is print a message such as "No action performed" (as an example) if none of the cases matched the random number. Is there an easy way to do this?

    Thanks.
    Last edited by R0bert0; 07-16-2011 at 03:36 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    You can add

    Java Code:
    default:
        whatever();
        break;

Similar Threads

  1. Probably a newbie question.... :P
    By gblax123 in forum New To Java
    Replies: 9
    Last Post: 02-23-2011, 11:21 PM
  2. Newbie Question using the less than < operator
    By mancsta in forum New To Java
    Replies: 1
    Last Post: 12-02-2010, 12:27 AM
  3. Newbie question
    By MrNiceGuy in forum New To Java
    Replies: 8
    Last Post: 11-12-2010, 06:29 AM
  4. newbie question
    By ronguilmet in forum New To Java
    Replies: 2
    Last Post: 11-16-2009, 03:37 AM
  5. Replies: 2
    Last Post: 11-22-2008, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •