Department of Computer Science
CSC-231
Object Oriented Programming
LAB 02
Operators, Selection Building Blocks, Case Control Structure, Loops and Arrays
Operators in Java:
Operator in Java is a symbol which is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in Java which are given below:
Unary Operators:
The unary operators require only one operand; they perform various operations such as
incrementing/decrementing a value by one, negating an expression, or inverting the value of a
boolean.
, IQRA UNIVERSITY
Department of Computer Science
CSC-231
Object Oriented Programming
Example 1: (UnaryOperator.java):
, IQRA UNIVERSITY
Department of Computer Science
CSC-231
Object Oriented Programming
Decision Making Structures:
Decision making structures requires the programmer to specify one or more conditions to
be evaluated or tested by the program, along with a statement or statements to be executed
if the condition is determined to be true, and optionally, other statements to be executed if
the condition is determined to be false.
If-else Statement:
The Java if statement is used to test the condition. It checks boolean condition: true or false.
There are various types of if statement in Java.
o if statement
o if-else statement
o if-else-if ladder
o nested if statement