In this Java examples of Java tutorial, we will study about Java subtraction operator OR Java minus operator with example. we will study what is the use of Java subtraction operator.

## Java Subtraction operator

Java Subtraction operator is used to subtract the two numbers and it gives the difference of that. Java Subtraction operator is written as

Java Subtraction operator | X – Y |

- Here X and Y are two numbers
- – is the java subtraction operator.

## Java Subtraction operator Example

Let’s understand Java subtraction operator with example.

public class JavaExamples { public static void main(String[] args) { //Java subtraction operator with example in Java int firstNumber=20; int secondNumber=18; int result=firstNumber - secondNumber; System.out.print("result is:"+result); } }

**output**

result is:2

**Explanation**

In above Java subtraction operator program, `firstNumber`

and `secondNumber`

are two integer variables. we applied Java subtraction operator on these two numbers. we save the result in `result`

variable.

In this Java operators with example, we saw how Java subtraction operator works with example.