Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    problem with logical operators

    import javax.swing.JOptionPane;

    public class Main {





    public static void main(String[] args) {
    int switch1 = 10;
    int switch2 = 20;
    }
    if(((switch1==1)&&(switch2==-1))||((switch1!=1)&&(switch2!=-1)))
    JOptionPane.showMessageDialog (null, "Trouble, the switches are the same!");

    else

    JOptionPane.showMessageDialog(null, "Ok the switches are different.");


    }
    }
    }


    The problem here is that the compiler keeps on saying that I need a bracket. Alternately, I add one, and the whole code just...is awash in red lines. Help?
    Last edited by dannyboi; 08-12-2012 at 03:09 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You're missing a brace, not a bracket.
    And where is "switch1" and "switch2" defined?

  • #3
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I have defined switch1 and switch2, now what?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You cannot just randomly add a location to put a closing brace.
    I think you better start here, and start under the trails covering the basics section: http://docs.oracle.com/javase/tutorial/


  •  

    Tags for this Thread

    Posting Permissions

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