Results 1 to 6 of 6
  1. #1
    mharckz009 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default How to compare variable with multiple variable?

    Hi!
    Can you help me how to compare my choose variable with multiple variable?
    which i can be used?
    because i used == but not working..


    this is my code

    Java Code:
    if(this.myPick == this.box1 && this.myPick == this.box2)
    {
    bet=bet*2;
    money=money+bet;
    System.out.println("You Got Double: " + bet);
    }
    
    else if(this.myPick == this.box2 && this.myPick == this.box3)
    {
    bet=bet*2;
    money=money+bet;
    System.out.println("You Got Double: " + bet);
    }
    
    else if(this.myPick == this.box3 && this.myPick == this.box1)
    {
    bet=bet*2;
    money=money+bet;
    System.out.println("You Got Double: " + bet);
    }
    
    else if(this.myPick == this.box1 && this.myPick == this.box2 && this.myPick == this.box3)
    {
    bet=bet*3;
    money=money+bet;
    System.out.println("You Got Triple: " + bet);
    }

  2. #2
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default Re: How to compare variable with multiple variable?

    I think I have done in my program the same but on a smaller scale.
    I have buttons that let the user select 2 options.

    Java Code:
    if (StringA == "YES") {
    			if (StringB == "YES") {
    				System.out.println("Yes, Yes");
    			}
    }
    Is that maybe what you would like?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: How to compare variable with multiple variable?

    Don't use == for comapring two Strings or other objects except when you really need to ascertain identity equality. Use the equals(...) method, which in a correctly written class, determines semantic equality: for Strings, that means the character content of the String.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: How to compare variable with multiple variable?

    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    mharckz009 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to compare variable with multiple variable?

    thanks
    can you correct my code because i can't imagine how..
    thank again.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: How to compare variable with multiple variable?

    The tutorial has examples of how to use methods:
    http://docs.oracle.com/javase/tutori...arguments.html
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 07-07-2012, 10:12 PM
  2. Dynamic variable name based on other variable
    By nadissen in forum Eclipse
    Replies: 4
    Last Post: 05-06-2011, 06:22 PM
  3. Replies: 11
    Last Post: 07-07-2010, 06:02 AM
  4. Issue with saving multiple times to a variable
    By sidd0123 in forum New To Java
    Replies: 3
    Last Post: 06-06-2010, 02:02 AM
  5. multiple declaration of a variable
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 09:17 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
  •