In the previous article, we have discussed about Java Program on Addition Operator
In this article we will see the use of Subtraction operator in Java.
Java Program on Subtraction Operator
Addition operator is a binary operator and it is used to subtract two numbers. Subtraction operator is represented by the -
symbol.
Syntax: operand - operand
Example:
Let’s understand it more clearly.
Suppose we have 2 variables a and b.
a=22
b=13
Then we can use subtraction operator like this.
result=a-b; // here 2 variable operand subtracted
(or)
result = 15 – b; // here one constant operand i.e. 15 and variable operand i.e. ‘b
‘ subtracted
Program:
import java.io.*; class Main { public static void main(String[] args) { //Declaring variables int number1 = 100; int number2 = 20; //subtracting two numbers by using subtraction operator int result = number1-number2; //print results System.out.println("By performing subtraction operation: " + result); } }
Output: By performing subtraction operation: 80
Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples
Related Java Programs: