Java Math Operators and special operators

Photo by Chris Liverani on Unsplash
  1. Addition.
  2. Subtraction.
  3. Multiplication
  4. Division
  5. Remainder
  6. Special operators

Addition

We perform addition by using + operator on numeric data types

Subtraction

We perform addition by using operator on numeric data types

Multiplication

We perform multiplication by using * operator on numeric data types

Division

We perform division by using / operator on numeric data types

Remainder

The remainder operator will calculate what remains after division. % — this is the remainder.

Special operators

Regular:

With special operator:

Both above examples are doing the exact same thing — adding 2 to our i variable.

Regular:

With special operator:

Increment and Decrement operators

The increment operator will increase the value of a numeric variable by 1.

  • post-increment (++ after variable) will increase value in the next statement.
  • pre-increment will increase value immediately.

The decrement operator will decrease the value of a numeric variable by 1.

  • post-decrement(after variable) will decrease value in the next statement.
  • pre-decrement will decrease value immediately.

This article is part of the series of articles to learn Java programming language from Tech Lead Academy.

Software Developer, Java Instructor https://www.techleadacademy.io/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store