Java Mathematical Operators

Java Mathematical Operators

Five mathematical operators are available:
  1. addition (+),
  2. subtraction (–),
  3. multiplication (*),
  4. division (/),
  5. and modulus (%).
Mathematical operators example:
public class MathDemo {

  public static void main(String[] args) {
    long result;
    result = 56 + 32;     // result = 88
    System.out.println("result = " + result);
    result = 44 - 23;     // result = 21
    System.out.println("result = " + result);
    result = 21 / 7;      // result = 3
    System.out.println("result = " + result);
    result = 12 * 4;     // result = 48
    System.out.println("result = " + result);
    result = 21 % 4;     // result = 1
    System.out.println("result = " + result);
  }
}
The result of this is:
result = 88
result = 21
result = 3
result = 48
result = 1
You can download this example here (needed tools can be found in the right menu on this page).
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.