- Info:

- This tutorial shows how to use Arithmetic Operators in JAVA.: - + - * / % ++ -- !.

- If one of the operands is float or double the other one is implicitly transformed into that type.

- Example:

- Create C Console Application Test.c.

Test.c

#include <stdio.h>

int main() {

int     x          = 10;

int     y          = 20;

int     negate     =  -y;        /* -20       = -20                                    */

int     add        = x+y;        /* 10+20     =  30                                    */

int     subtract   = x-y;        /* 10-20     = -10                                    */

int     multiply   = x*y;        /* 10*20     =  200                                   */

int     divide1    = x/y;        /* 10/20     =  0.5     = 0                           */

float   divide2    = (float)x/y; /* 10.0/20.0 =  0.5                                   */

int     reminder   = x%y;        /* 10%20     =  0*20+10 = 10                          */

int     increment1 = ++x;        /* Increment x by 1 and then store x into increment1. */

int     decrement1 = --x;        /* Decrement x by 1 and then store x into decrement1. */

int     increment2 =   x++;      /* Store x into increment2 and then increment x by 1. */

int     decrement2 =   x--;      /* Store x into decrement2 and then decrement x by 1. */

printf("%i\n",negate    );

printf("%i\n",subtract  );

printf("%i\n",multiply  );

printf("%i\n",divide1   );

printf("%f\n",divide2   );

printf("%i\n",reminder  );

printf("%i\n",increment1);

printf("%i\n",decrement1);

printf("%i\n",increment2);

printf("%i\n",decrement2);

return 1;

}