Explain the various Expressions of Java.
Advertisements
Question
Explain the various Expressions of Java.
Explain
Advertisements
Solution
- Arithmetic Expressions: These expressions are used to perform mathematical calculations such as addition, subtraction, multiplication, division and modulus.
Example:a + b * c - Relational Expressions: These expressions are used to compare two values or variables. They return a Boolean result, either
trueorfalse.
Example:a > b - Logical Expressions: These expressions are used to combine or reverse Boolean conditions using logical operators such as AND (
&&), OR (||) and NOT (!).
Example:(a > b) && (a > c) - Assignment Expressions: These expressions are used to assign a value or the result of an expression to a variable using assignment operators.
Example:a = b + 10 - Conditional Expressions: These expressions use the ternary operator (
? :) to select one of two values depending on whether a condition istrueorfalse.
Example:max = (a > b) ? a : b - Bitwise Expressions: These expressions are used to perform operations on the individual bits of integer values using bitwise operators.
Example:a & b
shaalaa.com
Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]
