Operators
We use the operators to make operations with the basic types of Java. Let’s see them:
Simple assignment: It assigns a value to a variable, you can assign a new value in the variable.
Compound assignment: Other way to assigns values:
a (sign)=b this means a = a (sign) b, the sign can be:
- ( + ) to add
- ( – ) to substract
- ( * ) to multiply
- ( / ) to divide
- ( % ) to return the raminder
Arithmetic operators: These are used for mathematical calculations the simplest:
Additions, subtraction multiplication, and division. (+,-,*,/).
6/2*2+5-2 the result is = 9
Power (**)
2**4 = 2^4 the result is 16
Modulus (%)
5%2 the result is 1, it returns the reminder of 5/2
Comparison operators:
These operations returns a Boolean so, it returns true or false:
- Equality “==”
If the values are the same return true instead return false
- Compare <,<=,>,>=
ab If a is smaller or bigger than b.
a<=b / a>=b if a is smaller/bigger or same than b.
Logic operators:
These returns true or false, an it follows the rules of the table of truth. This is the basic structure: condition1 (operator) condition2