Results 1 to 8 of 8
  1. #1
    L2Code is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Couple questions

    How do I use if and else if to play a game of rock paper scissors?

    JOptionPane.showInputDialog("Enter rock, paper, or scissors");
    JOptionPane.showInputDialog("Enter rock, paper, or scissors");

    Now after this I have to write the if statements but dont understand how to do so to make it work. So far one person enters one of the options then hits okay then the other person would have to do the same then hit okay. I then need the program to figure out who wins and pops up another Dialog box telling the winner.

    My next problem is this (code below). I wrote code using if statements to order numbers in numerical order but the program doesnt run any of my JOptionPanes even though its not giving me any errors or anything. I understand there are other possible ways of ordering numbers but this is the way I have to do it right now. What's my problem?
    Thanks!

    if (number1 > number2)
    if (number2 > number3)
    JOptionPane.showMessageDialog(null," "+ number1 + "," + number2 + "," + number3);
    else
    if (number1 > number2)
    if (number2 < number3)
    JOptionPane.showMessageDialog(null," "+ number1 + "," + number3 + "," + number2);
    else
    if (number1 < number2)
    if (number2 < number3)
    JOptionPane.showMessageDialog(null," "+ number3 + "," + number2 + "," + number1);
    else
    if (number1 > number2)
    if (number2 < number3)
    if (number1 < number3)
    JOptionPane.showMessageDialog(null," "+ number3 + "," + number1 + "," + number2);
    else
    if (number1 < number2)
    if (number2 > number3)
    if (number1 > number3)
    JOptionPane.showMessageDialog(null," "+ number2 + "," + number1 + "," + number3);
    else
    if (number1 < number2)
    if (number2 > number3)
    if (number1 < number3)
    JOptionPane.showMessageDialog(null," "+ number2 + "," + number3 + "," + number1);
    Last edited by L2Code; 03-22-2013 at 07:27 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Couple questions

    My first advice is to use curly brackets and indentation to organize your if/else blocks better.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    L2Code is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Couple questions

    Quote Originally Posted by KevinWorkman View Post
    My first advice is to use curly brackets and indentation to organize your if/else blocks better.
    Well besides organization.......

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Couple questions

    Crossposted: Help my if statements!

    I really can't help you until you fix your formatting.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    L2Code is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Couple questions

    Quote Originally Posted by KevinWorkman View Post
    Crossposted: Help my if statements!

    I really can't help you until you fix your formatting.

    Got it! hahah.

    Okay onto the rock,paper,scissors? I have no idea how to start if statements for that
    Last edited by L2Code; 03-22-2013 at 08:37 PM.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Couple questions

    Quote Originally Posted by L2Code View Post
    When I try adding curly brackets around each section it tells me there is a syntax error on the token else and to delete it.
    Exactly. I think you're making a mistake with lining up your sections. Adding the brackets will clear that up.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    L2Code is offline Member
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: Couple questions

    Is it suppose to work without the "else" in there? Because I tried to just delete them after I put the brackets in there because of the syntax error that was coming up and now it works ( or so it seems so far).

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Couple questions

    Quote Originally Posted by L2Code View Post
    Is it suppose to work without the "else" in there? Because I tried to just delete them after I put the brackets in there because of the syntax error that was coming up and now it works ( or so it seems so far).
    I don't really know whether it's supposed to work or not- you tell us. Also, I suggest posting your updated code, so everybody is looking at the same thing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Couple of Generics questions
    By UAF in forum Advanced Java
    Replies: 3
    Last Post: 03-31-2011, 09:37 AM
  2. Couple questions about Java
    By theadolescent in forum New To Java
    Replies: 3
    Last Post: 05-19-2010, 02:13 AM
  3. Couple Questions on Thread
    By Lil_Aziz1 in forum Threads and Synchronization
    Replies: 5
    Last Post: 01-06-2010, 02:02 PM
  4. Couple of questions regarding threading
    By exernet in forum New To Java
    Replies: 1
    Last Post: 12-15-2009, 12:23 PM
  5. Couple of newbie questions
    By ananasman in forum New To Java
    Replies: 11
    Last Post: 11-20-2008, 11:54 PM

Posting Permissions

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