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

Thread: How to compare variable with multiple variable?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

    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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to compare variable with multiple variable?

    The == operator is for comparing primitives. The equals() method is for comparing the contents of objects.
    What is the code comparing? Primitives or object contents?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to compare variable with multiple variable?

    thank for reply
    ok, what should i use..how to use that equals()..?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to compare variable with multiple variable?

    Use equals like any other method: var.equals(vsr2)

    Also posted at http://www.java-forums.org/new-java/...-variable.html
    Last edited by Norm; September 11th, 2012 at 09:07 AM.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. For-loop: initialisation of variable, can't set variable to value zero?
    By Bitbot in forum Loops & Control Statements
    Replies: 4
    Last Post: July 15th, 2012, 02:32 PM
  2. [SOLVED] Assign a loop to variable to compare strings
    By norske_lab in forum Loops & Control Statements
    Replies: 3
    Last Post: March 6th, 2012, 02:46 PM
  3. Replies: 5
    Last Post: November 16th, 2011, 11:22 AM
  4. [SOLVED] what is this? Variable?
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 7th, 2011, 11:32 PM
  5. Reset the value of each variable
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 22nd, 2009, 09:45 AM