# Logical Operators

• 03-26-2012, 03:04 PM
Everyman
Logical Operators
How would I write an expression that evaluates to true if x is non-negative and y is negative when they have already been declared and assigned values?
• 03-26-2012, 03:12 PM
KevinWorkman
Re: Logical Operators
What have you tried? Where are you stuck?

How do you test whether a value is negative or not?
• 03-26-2012, 03:19 PM
Everyman
Re: Logical Operators
Quote:

Originally Posted by KevinWorkman
What have you tried? Where are you stuck?

How do you test whether a value is negative or not?

I have been working with Equality and Rational Operators for the past few days, and this is my first time being exposed to this type of material. I have no idea how to test whether the value is negative or not, and the I have tried this:

"!-x"
"!-y"
• 03-26-2012, 03:23 PM
KevinWorkman
Re: Logical Operators
• 03-26-2012, 03:27 PM
Everyman
Re: Logical Operators
Quote:

Originally Posted by KevinWorkman

When it is below zero, right?
• 03-26-2012, 03:30 PM
KevinWorkman
Re: Logical Operators
Quote:

Originally Posted by Everyman
When it is below zero, right?

Seems reasonable to me. Now do you see any comparative operators that test whether a value is less than another value?

• 03-26-2012, 03:34 PM
Everyman
Re: Logical Operators
Quote:

Originally Posted by KevinWorkman
Seems reasonable to me. Now do you see any comparative operators that test whether a value is less than another value?

The tutorial I linked you to contains this page: Equality, Relational, and Conditional Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

These?:

"< less than"
"<= less than or equal to"
• 03-26-2012, 03:36 PM
KevinWorkman
Re: Logical Operators
Quote:

Originally Posted by Everyman
These?:

"< less than"
"<= less than or equal to"

What happened when you tried them?
• 03-26-2012, 03:42 PM
Everyman
Re: Logical Operators
Quote:

Originally Posted by KevinWorkman
What happened when you tried them?

Good things. Good things happened, sir. Thank you for all of your help.

P.S.: This is the code that I used (x>=0 && y<0)
• 03-26-2012, 03:56 PM
KevinWorkman
Re: Logical Operators
Awesome. Glad you got it sorted out.