Page 249 - PowerPoint Presentation
P. 249
CAVITE STATE UNIVERSITY
TRECE MARTIRES CITY CAMPUS
Department of Information Technology DCIT 111 - Advanced Programming
Week 4: Elements of Programming Languages Continuation
Objective: After the completion of the chapter, students will be able to:
Learn the fundamentals of High-level programming language
Perform different operations and instructions using High-level programming language
Create a simple program applying conditional statements, looping and array.
Write program codes in a piece of paper
Java Relational Operator
Relational Operators are also called comparison operators, are used to determined
the relationship between two values in an expression. Relational Operators are commonly
used in Conditional Statements (if, if-else, if-else ladder).
Operator Operation Returns True if..
> A > B A is greater than B
>= A >= B A is greater than or equal to
B
< A < B A is less than B
<= A <= B A is less than or equal to B
== A == B A and B are equal
!= A != B A are not equal to B
Example:
class ConditionalExample { //use of Relational Operators
public static void main(String[]args) {
int a=10, b=5;
if (a > b) {
System.out.println(“A is greater than B”);
} }
Java Logical Operators
Logical operators are used to combine multiple (two or more) expressions to return a
single value that evaluates o either true or false.
Operator Operation Description
&& A && B Conditional AND: if both A and B are true, result is true, if either A
or B is false, the result is false. But if A is false, B will not be
evaluated. For example, A>4 and B<10) will evaluate to true if A is
greater than 4 and B is less than 10.
|| A || B Conditional OR: if either A or B is true, the result is true. But if A is
true, B will not be evaluated. For example, (A>10 || B>10) will be
evaluate to true if either A or B are greater than 10
! !A Boolean NOT: if A is true, the result is false, if A is false, the result
is true.
& A & B Boolean AND: if both A and B are true, the result is true. If either
A or B are false and both A and B are evaluated before the test.
| A | B Boolean OR: If either A or B are true, the result is true. Both A and
B are evaluated before the test.
^ A ^ B Boolean XOR: If a is true and B is false, the result is true. If A is
false and B is true, the result is true. Otherwise, the result is false.
Both A and B are evaluated before the test.
25