Logical operators:
It is common to want to combine the results from several logical expressions. For example, we may want to allow a user to log in only if the username is recognized and the password is correct. Java provides logical operators, which roughly correspond to the natural language words 'and', 'or' and 'not', as a way of combining logical expressions.
The logical operators are summarized in Table. This shows the use of the arguments a and b.
The arguments for a logical operator must be logical expressions.
As we have just seen, one way of forming a logical expression is using relational operators and variables with numeric types. It is possible for us to combine several conditions into one statement using the logical operators. For example, consider the code shown below:
int a, b;
boolean eitherPositive, bothNegative;
a = 22;
b = -33;
eitherPositive = (a > 0) || (b > 0);
bothNegative = (a < 0) && (b < 0);
The variable eitherPositive is assigned the value true, because a > 0 is true and therefore the whole expression is true (even though b > 0 is false). Only one part of an OR expression need be true for the whole expression to be true.
The variable bothNegative is assigned the value false because a < 0 is false, and therefore the whole expression is false. Even though b< 0 is true, this is not sufficient for the AND expression to be true.
Java Assignment Help - Java Homework Help
Struggling with java programming language? Are you not finding solution for your Logical operators homework and assignments? Live Logical operators experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Logical operators homework help, java assignment help and Logical operators projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving java programming language queries in excels and word format.
- Best tutoring assistance 24x7 hours