FontysICT-sem1

Basic knowledge: Int and double operations (operators)

The operations below apply to both int types and to double types:

int k;
k = 5 + 10;

Variable k is assigned the value 15 in the last line of code because the + sign adds the values 5 and 10 together.

int i = 2;
int k;
k = i + 1;

Variable k is assigned the value 3 in the last line of code because the + sign adds the values 2 and 1 together.

int i = -8;
int k;
k = 1 + i;

Variable k is assigned the value -7 in the last line of code because the + sign adds the values 1 and -8 together.

int i = 5;
int j = 3;
int k;
k = i + j;

Variable k is assigned the value 8 in the last line of code because the + sign adds up the values from i and j. In the above examples, the operator (the + sign) can be can be replaced with one of the following:

symbol elaboration .
+ Add  
- Subtraction  
* Multiply  
/ Divide  
% Returns the remainder after division. For example:  
  7 % 5 = 2  
  11 % 2 = 1  
  6 % 2 = 0