0% found this document useful (0 votes)
15 views2 pages

Java Operators Explained: Types & Examples

The document outlines various operators in programming, including arithmetic, relational, logical, increment/decrement, assignment, operator precedence, conditional, bitwise, type casting, and combined operators. It provides examples with specific variable values and asks for the results of different operations. Each section includes calculations or boolean evaluations based on the given inputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Java Operators Explained: Types & Examples

The document outlines various operators in programming, including arithmetic, relational, logical, increment/decrement, assignment, operator precedence, conditional, bitwise, type casting, and combined operators. It provides examples with specific variable values and asks for the results of different operations. Each section includes calculations or boolean evaluations based on the given inputs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1.

Arithmetic Operators:
Given: int a = 15; and int b = 4;
What are the values of:
* a / b
* a % b
* (double) a / b
2. Relational Operators:
Given: int a = 15; and int b = 4;
What is the boolean result of each expression?
* a > b
* a == b
* a != b
* a <= 15
3. Logical Operators:
Given: boolean isJavaFun = true; and boolean isCoffeeHot = false;
What is the boolean result of each expression?
* isJavaFun && isCoffeeHot
* isJavaFun || isCoffeeHot
* !isJavaFun
4. Increment/Decrement Operators:
What is the final value of j?
int i = 5;
int j = ++i;

What is the final value of k?


int i = 5;
int k = i++;

5. Assignment Operators:
Given: int x = 10;
What is the value of x after the following operations?
* x += 5;
* x -= 2;
* x *= 3;
6. Operator Precedence:
What is the value of result?
int result = 10 + 2 * 5 - 12 / 3;
7. Conditional (Ternary) Operator:
What is the value of message?
int age = 18;
String message = (age >= 18) ? "You can vote." : "You cannot vote.";

8. Bitwise Operators:
Given: int x = 10; and int y = 5;
What is the value of:
* x & y
* x | y
* x ^ y
9. Type Casting:
What is the output of the following code?
double myDouble = 123.456;
int myInt = (int) myDouble;
[Link](myInt);

10. Combined Operators:


What is the final value of total?
int total = 100;
total /= 10;
total++;
total %= 3;

You might also like