0% found this document useful (0 votes)
6 views

Java Operators

Here are the programs to solve the problems: 1. length = 15 breadth = 27 area = length * breadth perimeter = 2 * (length + breadth) print("Area is:", area) print("Perimeter is:", perimeter) 2. num1 = 35 num2 = 75 if num1 == num2: print("Numbers are equal") else: print("Numbers are not equal")

Uploaded by

milliongate1122
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Java Operators

Here are the programs to solve the problems: 1. length = 15 breadth = 27 area = length * breadth perimeter = 2 * (length + breadth) print("Area is:", area) print("Perimeter is:", perimeter) 2. num1 = 35 num2 = 75 if num1 == num2: print("Numbers are equal") else: print("Numbers are not equal")

Uploaded by

milliongate1122
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

JAVA

OPERATORS
Operators
are symbols that carry out mathematical or logical functions
on an operand or operands such as literals, constants,
variables and objects.

Unary Operators
bitwise complement (~), negation (-), increment (++) and
decrement (- -) have only one operand. They can change
their operand's value without the use of an assignment
operator (=).
Binary Operators
have exactly two operands and uses the assignment
operator for the result.

Ternary Operators
has at most three operands. In Java, the only ternary
operator is the conditional operator (? :).
Arithmetic Operators
Operators Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
++ Increment
-- Decrement
Relational Operators
are considered as binary operators since they
show the relationship between two operands. It
yield a true or false value.
Operators Description
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not Equal to
Logical Operators
as logical operators are governed by logical rules,
truth tables are necessary to evaluate logical
operations. It is strongly suggested that the
programmer keeps the ff. truth tables in mind
when evaluating logical operations.

Operators Description
! NOT
& AND
| OR
&& short-circuit AND
|| short-circuit OR
AND
The binary operator AND operator returns false
except when both operands have a true value.

Operand1 Operand2 Result


false & true false
false & false false
true & false false
true & true true
OR
The binary operator OR operator evaluates to true
except when both operands are false.

Operand1 Operand2 Result


false | true true
true | true true
true | false true
false | false false
XOR
The binary operator XOR (^) returns true except
when both operands does not have the same
value.

Operand1 Operand2 Result


true ^ false true
false ^ true true
false ^ false false
true ^ true false
NOT
The unary NOT (!) operator is complimentary.

Operand2 Result
! false true
! true false
Coding Time:
1. Length and breadth of a rectangle are
15 and 27 respectively. Create a
program that will calculate the area
and perimeter of the rectangle.
2. Create a program to check if the two
numbers 35 and 75 are equal.

You might also like