Operators

Logical operators

// !expr inverts the expression (changes false to true, and vice versa) // || logical OR // && logical AND bool isOutOfStock = false; int quantity = 3; if (!isOutOfStock && (quantity == 2 || quantity == 3)) { // ...Order the product... } 

Equality and relational operators

print(2 == 2); //Print: true - Equal print(2 != 3); //Print: true - Not Equal print(3 > 2); //Print: true - Grater than print(2 < 3); //Print: true - Less than print(3 >= 3); //Print: true - Greater than or equal to print(2 <= 3); //Print: true - Less than or equal to 

Arithmatic Operators

print(2 + 3); //Print: 5 print(2 - 3); //Print: -1 print(2 * 3); //Print: 6 print(5 / 2); //Print: 2.5 - Result is a double print(5 ~/ 2); //Print: 2 - Result is an int print(5 % 2); //Print: 1 - Remainder int a = 1, b; // Increment b = ++a; // preIncrement - Increment a before b gets its value. b = a++; // postIncrement - Increment a AFTER b gets its value. //Decrement b = --a; // predecrement - Decrement a before b gets its value. b = a--; // postdecrement - Decrement a AFTER b gets its value. 
Comments