Selection.pptx
Selection.pptx
Programming in Java
Selection
Rabea Khatun
Lecturer
Dept. Of CSE
East West University
tru fals
e e
Statement Block
1 grade = 95;
2 If (grade>= 90)
3 System.out.println("You got an
"A");
Statement 4 System.out.println("This is line 4");
Rabea Khatun, Lecturer,CSE, East West University 5
Boolean Expressions
== equal to
!= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
Note the difference between the equality operator (==) and
the assignment operator (=)
! Not
*, /, % Math operators
+, - Math operators
<, <=, >, >= Relational operators
==, != Relational equality
^ Exclusive OR
&& Logical AND
|| Logical OR
=, +=, -=, *=, /=, %= Assignment
operators
condition
evaluated
tru fals
e e
StatementBlock1 StatementBlock2
Statement
Rabea Khatun, Lecturer,CSE, East West University 12
The if-else Statement
• Another example:
if (i > 0) {
System.out.println("i is positive");
}
Same as
if (i > 0)
System.out.println("i is positive");