Results 1 to 5 of 5
  1. #1
    malaguena is offline Member
    Join Date
    Mar 2011
    Posts
    24
    Rep Power
    0

    Default Multiple comparisons

    Hello,

    How can we compare more than two integers in an if statement?

    For example;

    if(a==b==c==d==e)

    This gives an error since the first operation gives a boolean result and tries to compare it with the next integer.

    Thanks..

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Use logical operations && ||
    For example
    Java Code:
    if (a==b && b==c && c==d && d==e)
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    The == operator takes two operands.
    Break your expression up into pairs of operands and connect with ANDs.
    a==b && b==c ...

  4. #4
    malaguena is offline Member
    Join Date
    Mar 2011
    Posts
    24
    Rep Power
    0

    Default

    Thank you very much for the replies!

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

Similar Threads

  1. Multiple BufferedReaders?
    By sehudson in forum New To Java
    Replies: 1
    Last Post: 03-01-2011, 05:40 PM
  2. Multiple JFrames
    By frguy in forum Advanced Java
    Replies: 11
    Last Post: 01-08-2011, 10:36 AM
  3. Running multiple threads on multiple CPU cores?
    By Dosta in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-19-2010, 03:48 PM
  4. Multiple SwingWorkers
    By Arne in forum Threads and Synchronization
    Replies: 12
    Last Post: 08-26-2010, 02:54 AM
  5. Keeping track of Copies + Comparisons in Sort Methods
    By VinceGuad in forum New To Java
    Replies: 0
    Last Post: 03-12-2009, 04:07 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
  •