Java mathematical operators

 


MATHEMATICAL OPERATIONS.

Java provides a rich set of operators to use in manipulating variables. A value used on either side of the operator is called an operand

Take an example

              public class mathoperators{

                              public static void main (String[] arg) {

                              int x = 6+5;

                              System.out.println(x);

             //the output will display 11

}

}

 

Java Arithmetic Operators

+ addition

  -  substraction

  * multiplication

  / division

  % modulo

 

 Arithmetic operations are used in mathematical expressions in the same way that are used in algebraic equations. I will explain about modulo only cause I find it kind of confusing. The rest of the operators you can digest them on you own its grade three mathematics.

 

MODULO (%)

Another name is called a remainder. Is a math operation performs an integer division of one value by another and returns the remainder of that division. It is denoted by the percentage symbol.

EXAMPLE

                int value = 23

                int res = value % 6;

// res is 5

 video here

Dividing 23 by 6 returns a quotient of 3 with a remainder of 5. Thus the value of 5 is assigned to the res variable.

Comments