24 Questions
What is the result of the expression 'c = a + b'?
30
What happens when you use the '=>' operator in Java?
It is not a valid operator in Java.
What is the purpose of the '+' operator in Java?
It performs an addition operation.
What is the result of the expression 'c /= a'?
1
What is the purpose of the '%' operator in Java?
It performs a modulus operation.
What is the result of the expression 'c %= a'?
5
What is the purpose of the '>>' operator in Java?
It performs a bitwise right shift operation.
What is the purpose of the '^' operator in Java?
It performs a bitwise XOR operation.
What is the result of the expression a & b?
12
What is the result of the expression a ^ b?
49
What is the result of the expression ~a?
-61
What is the result of the expression a >>> 2?
a / 4
What is the condition for the Logical AND operator (&&) to be true?
If both the operands are non-zero
What is the function of the Logical NOT operator (!)?
To reverse the logical state of its operand
What is the result of the expression a && b
in the given Java program?
false
What is the purpose of the +=
operator in Java?
To add and assign the result to the left operand
What is the result of the expression a || b
in the given Java program?
true
What is the purpose of the &=
operator in Java?
To perform bitwise AND operation
What is the result of the expression !(a && b)
in the given Java program?
true
What is the purpose of the /=
operator in Java?
To perform division
What is the purpose of the %=
operator in Java?
To perform modulus
What is the purpose of the ^=
operator in Java?
To perform bitwise XOR operation
What is the purpose of the |=
operator in Java?
To perform bitwise OR operation
What is the purpose of the =
operator in Java?
To assign values from the right side operand to the left side operand
Study Notes
Operators in Java
- Java program demonstrates the use of various operators:
- Arithmetic operators:
+
,-
,*
,/
,%
- Assignment operators:
=
,+=
,-=
,*=
,/=
,%=
,&=
,^=
,|=
- Miscellaneous operators:
>>
,~
,!
- Arithmetic operators:
Assignment Operators
- Simple assignment operator:
=
- Assigns values from right-side operands to left-side operands
- Example:
C = A + B
will assign the value ofA + B
intoC
- Add AND assignment operator:
+=
- Adds right operand to the left operand and assigns the result to left operand
- Example:
C += A
is equivalent toC = C + A
- Subtract AND assignment operator:
-=
- Subtracts right operand from the left operand and assigns the result to left operand
- Example:
C -= A
is equivalent toC = C - A
- Multiply AND assignment operator:
*=
- Multiplies right operand with the left operand and assigns the result to left operand
- Example:
C *= A
is equivalent toC = C * A
- Divide AND assignment operator:
/=
- Divides left operand with the right operand and assigns the result to left operand
- Example:
C /= A
is equivalent toC = C / A
- Modulus AND assignment operator:
%=
- Takes modulus using two operands and assigns the result to left operand
- Example:
C %= A
is equivalent toC = C % A
- Bitwise AND assignment operator:
&=
- Example:
C &= 2
is same asC = C & 2
- Example:
- Bitwise exclusive OR and assignment operator:
^=
- Example:
C ^= 2
is same asC = C ^ 2
- Example:
- Bitwise inclusive OR and assignment operator:
|=
- Example:
C |= 2
is same asC = C | 2
- Example:
Logical Operators
- Logical AND operator:
&&
- If both operands are non-zero, then the condition becomes true
- Example:
(A && B)
is false
- Logical OR operator:
||
- If any of the two operands are non-zero, then the condition becomes true
- Example:
(A || B)
is true
- Logical NOT operator:
!
- Reverses the logical state of its operand
- Example:
!(A && B)
is true
Conditional Operator
- Also known as the ternary operator
- Consists of three operands and is used to evaluate Boolean expressions
- The goal of the operator is to decide which value should be assigned to the variable
- Example:
variable x = (expression) ? value1 : value2
Miscellaneous Operators
- Conditional operator:
?:
- Used to evaluate Boolean expressions
- Bitwise operators:
~
,>>
- Example:
a >>> 2
- Example:
This quiz is about understanding the usage of operators and assignment in Java programming, including addition, subtraction, and increment/decrement operations. It involves a Java program that demonstrates the use of these operations.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free