Java Operators Quiz

UndauntedMarsh2324 avatar
UndauntedMarsh2324
·
·
Download

Start Quiz

Study Flashcards

11 Questions

What is the result of the AND operation between 'true' and 'false'?

false

For the XOR operation, when does it return 'false'?

When both operands are true

What is the result of applying the NOT operator twice (!!) on 'true'?

true

What is the perimeter of a rectangle with length 15 and breadth 27?

78 units

In a rectangle with length 15 and breadth 27, what is the area?

405 square units

Which of the following is a unary operator in Java?

++

What is the purpose of the modulo operator (%)?

It performs division and returns the remainder.

Which of the following is a ternary operator in Java?

?:

What is the result of the expression 5 > 3 && 2 < 4?

true

Which of the following relational operators checks for equality?

==

What is the result of the expression !false?

true

Study Notes

Binary Operators

  • The binary operator AND (&) evaluates to true only when both operands have a true value.
  • The binary operator OR (|) evaluates to true except when both operands are false.
  • The binary operator XOR (^) returns true except when both operands have the same value.

Unary Operators

  • The unary NOT (!) operator is complimentary, switching true to false and false to true.

Operators in Java

  • Operators are symbols that carry out mathematical or logical functions on an operand or operands.
  • Types of operators in Java:
    • Unary Operators: have only one operand, e.g., bitwise complement (~), negation (-), increment (++) and decrement (--).
    • Binary Operators: have exactly two operands, e.g., arithmetic, relational, and logical operators.
    • Ternary Operators: have at most three operands, e.g., the conditional operator (?:).

Arithmetic Operators

  • Operators: +, -, *, /, %, ++, --
  • Descriptions:
    • Addition: +
    • Subtraction: -
    • Multiplication: *
    • Division: /
    • Modulo: %
    • Increment: ++
    • Decrement: --

Relational Operators

  • Operators: <, >=, ==, !=, >, <=
  • Descriptions:
    • Less than: <
    • Less than or equal to: <=
    • Greater than: >
    • Greater than or equal to: >=
    • Equal to: ==
    • Not Equal to: !=
  • Relational operators are binary operators that yield a true or false value.

Logical Operators

  • Operators: !, &, |, &&, ||
  • Descriptions:
    • NOT: !
    • AND: &
    • OR: |
    • Short-circuit AND: &&
    • Short-circuit OR: ||
  • Logical operators are governed by logical rules, and truth tables are necessary to evaluate logical operations.

Coding Exercises

  • Calculate the area and perimeter of a rectangle with length 15 and breadth 27.
  • Check if the two numbers 35 and 75 are equal.

Test your knowledge on Java operators which are symbols that perform mathematical or logical functions on operands. Learn about unary operators like bitwise complement, negation, increment, and decrement, binary operators with two operands, and ternary operators with at most three operands.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser