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 2 of 2

Thread: Help my if statements!

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help my if statements!

    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);


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help my if statements!

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/70603-couple-questions.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] If and else if statements???
    By skeptile2 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 5th, 2013, 01:44 AM
  2. If Statements help
    By cowsquad in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 10th, 2013, 06:41 AM
  3. if else statements
    By mozyman in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 24th, 2010, 08:06 PM
  4. If statements
    By Scottj996 in forum Java Theory & Questions
    Replies: 1
    Last Post: August 16th, 2010, 10:09 AM
  5. Need help with While and For Statements
    By duckman in forum Loops & Control Statements
    Replies: 2
    Last Post: October 20th, 2009, 08:42 PM