[go: up one dir, main page]

0% found this document useful (0 votes)
22 views20 pages

LECTURE 04 Conditional Expressions Com Prog 1

Uploaded by

riahnamagtoto06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views20 pages

LECTURE 04 Conditional Expressions Com Prog 1

Uploaded by

riahnamagtoto06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

OPERATIONS

AND
EXPRESSIONS
Handout 04 - Midterm(Com Prog 1)
Agenda
Operators Expressions
Arithmetic Operators Arithmetic Expressions
Assignment Operators Assignment Expressions
Unary Operators Relational Expressions
Comparison Operators Logical Expressions
Shift Operator Conditional Expressions
Bitwise Operator
Logical Operator
Conditional Operator
Order of Precedence of Operators
OPERATORS

Operators are symbols used to compute and compare


values and test multiple conditions. Java supports
several categories of operators.
Arithmetic Operators
All mathematical operations are performed using
operators in this category. An operand is the value to be
computed.
The + Operator with Numeric
Data Types
Adding operands of the primitive numeric data type
results in a primitive numeric data type.
The + Operator with the String
Data Type
If both operands are strings, the + operator joins them
to display as a single output. If one of the operands is
a string object, the second operand is converted into a
string before joining them.
Assignment Operators
An assignment operator assigns the specific value,
variable, and/or functions to another variable.
Unary Operators
Compared to previous operators, this operator requires
only one operand.
Comparison Operators
All mathematical operations involving comparison
between values are performed using comparison
operators. It is also often called a relational operators.
Shift Operators
These operators work on bits of data. It involves moving
the bit pattern to the left or right. These operators
can only be used with integer data types
Shifting Positive Numbers
The int data type occupies four (4) bytes in the memory. The rightmost eight bits of
the number 9 are represented in binary as:

For the right shift, the bits of the left operand are shifted right. Using 𝑥 = 9 ≫ 2, the
result becomes 2:

For the left shift, the bits of the left operand are shifted left. Using 𝑥 = 9 ≪ 2, the
result becomes 40:
Bitwise Operators
Compared to previous operators, bitwise operators
perform operations bit-by-bit. These operators can be
applied to byte, int, short, long, and char data types.
Logical Operators
These are used to combine the results of Boolean
expressions. These operators share a likeness with
bitwise operators, but logical operators are limited to
Boolean expressions only.
Conditional Operator
This operator is used to control the flow of the program.
The ternary operator is used mainly in loop
statements.
Order of Precedence of Operators
Order of Precedence shows the hierarchy wherein an operation with
high precedence is performed before the others. The table shows
those with the same level of precedence are listed in the same row.
EXPRESSIONS
An expression is a combination of variables, constants, literals, and
operators to produce a single value. A simple 23 + 16 and x = -82 are
considered expressions.

In Java, an expression statement consists of an expression followed


by a semicolon (;) to evaluate an expression and disregard the
result.
Arithmetic Expression
It is an expression that returns a numeric value based on the
operators and operands used. For example:

Assignment Expression
It is an expression that involves assigning a value to a variable. For
example:
Relational Expression
It is an expression that compares values using relational operators.
For example:

Logical Expression
It is an expression involving logical operators. For example:
Conditional Expression
It is an expression involving the use of the ternary operator (?:) to
assign a value based on a condition. For example:
THANK
YOU

You might also like