Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Switch Statment

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Statment

    Hi i was just wondering if anyone had any solutions to changing this switch statement to an IF ELSE statement, solutions would be helpful.

    switch (option) {

    // add person
    case 1:
    addPerson();

    // shows the person added
    JOptionPane.showMessageDialog(null, "\nThe following person has been added: \n");
    printPerson(numberOfPersons - 1);

    break;

    // search person
    case 2:

    searchPerson();

    break;

    // prints all the people listed
    case 3:

    printAllPersons();

    break;

    // quits the program
    case 4:

    JOptionPane.showMessageDialog(null, "Program terminated...\nHave a nice day =]");

    // quit
    System.exit(0);

    break;

    default:
    // warn user that something has gone wrong
    JOptionPane.showMessageDialog(null, "You have entered invalid information mate! Please try again.");
    break;
    }
    }
    }


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Switch Statment

    why would you want to but,

    if(x == 1){
    }else if(x == 2){
    }...

    you get the idea

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Switch Statment

    I'm doing a project and it has to be with IF ELSE statements which is bugging me

Similar Threads

  1. How to Use the Java switch statement
    By JavaPF in forum Java Programming Tutorials
    Replies: 6
    Last Post: April 18th, 2013, 05:19 PM
  2. Having trouble with a While statment
    By java0 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 27th, 2010, 12:37 PM
  3. need help with JButton and switch statements
    By jjoubert in forum AWT / Java Swing
    Replies: 5
    Last Post: October 28th, 2009, 09:13 AM
  4. switch with Enums
    By chronoz13 in forum Loops & Control Statements
    Replies: 17
    Last Post: October 8th, 2009, 08:08 PM
  5. [SOLVED] Switch statement question
    By shikh_albelad in forum Loops & Control Statements
    Replies: 5
    Last Post: May 31st, 2009, 05:13 AM