JAVA – codewindow.in

Related Topics

JAVA Programming

  • Logical OR (||) operator: If the first operand is true, the result of the expression is always true, so the second operand is not evaluated at all. If the first operand is false, the second operand is evaluated to determine the final result. For example:

In this example, we use the bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise complement (~), left shift (<<), right shift (>>), and unsigned right shift (>>>) operators on two integers x and y. The results of each operation are printed to the console. Note that the bitwise operators work on the binary representation of the operands and can be used to perform low-level bit manipulation, such as setting or clearing individual bits, or extracting bit fields from larger values.

Here, condition is a boolean expression that is evaluated to either true or false. If the condition is true, expression1 is evaluated and its value is returned. If the condition is false, expression2 is evaluated and its value is returned.

Here’s an example of using the ternary operator in Java:

In this example, we have two integers x and y. We use the ternary operator to find the maximum value between the two integers. The condition (x > y) is evaluated first, and if it is true, the value of x is returned. If it is false, the value of y is returned. In this case, since x is greater than y, the value of x (i.e., 10) is assigned to max. The output of the program is:

      

Popular Category

Topics for You

Go through our study material. Your Job is awaiting.

Categories