Java Arithmetic Operators – Java example

 

Java Arithmetic Operators :

Java arithematic operators is explained in this part of the tutorial with the help of operators and variables.These operators are used in mathematical operators mostly they are numeric.

These operands cannot be used on other data types because they are only supported by numeric and also char variable.

 

  1. Addition Operator (+)
  2. Subtraction Operator (-)
  3. Division Operator (/)
  4. Multiplication Operator (*)
  5. Percentile Operator (%)
  6. Increment Operator (++)
  7. Decrement Operator (–)

Now lets get through each of these and way of using them through a small example and see the result

 

Addition (+) :

Adding up of two numbers is done with the help of this operand let’s start coding by initializing variables

public static int a;
public static int b;
public static int result;

 

assign values to the variables

a = 10;
b = 20;

 

then make the operation possible on them with the help of operand

result = a + b;

 

now print the output using System.out.println

System.out.println(result);

 

 // addition operation

 a = 10;
 b = 20;

result = a + b;

System.out.println(result);

 

Java Arithmetic Operators

 

Subtraction (-):

Simple subtraction of two numbers is shown with the help of operand and variables.

// substraction operation

 a = 20;
 b = 10;

result = a - b;

System.out.println(result);

 

Java Arithmetic Operators

 

Division (/):

Division operand is explained with the help of a example.

// division operation

a = 10;
b = 2;

result = a / b;

System.out.println(result);

 

Java Arithmetic Operators

 

Multiplication (*):

Multiply of two numbers in java using ‘*’ operand is shown

// multiplication operation

a = 10;
b = 10;

result = a * b;

System.out.println(result);

 

Java Arithmetic Operators

 

Percentile (%):

Percentile of two number is calculated here

// percentage operation

 a = 100;
 b = 5;

result = b % a;

System.out.println(result);

 

Java Arithmetic Operators

 

Increment Operator (++):

Incrementing a number is show here we mostly use them in loops

// incremental operation

 a = 10;

result = ++a;

System.out.println(result);

 

Java Arithmetic Operators

 

Decrement (- -):

Decrement operator is explained here with a example

// decremental operation

 a = 15;

result = --a;

System.out.println(result);

 

Java Arithmetic Operators

 

Any query on Java Arithmetic Operators let us know in the comment section below.

For more interesting tutorials do like and share this tutorial.

 

Show Buttons
Hide Buttons
Read previous post:
Java String Concatenation – Java example

In this part of tutorial we will learn java string concatenation. So when we have to add up two String's...

Close