Subtraction Operator Example Java Program


Definition

Operators in Java are similar to those in C++. However, there is no delete operator due to garbage collection mechanisms in Java, and there are no operations on pointers since Java does not support them. Subtraction operator is an unary minus operator.

Syntax

data_type variable_name1= variable_name2 - variable_name3;

Subtraction Operator Example Program

class SubtractionOperator{
	public static void main(String[] args){
		int num1,num2,result;
		num1=12;
		num2=8;
		System.out.println("num1=12; num2=8");
		result=num1-num2;
		System.out.println("The result after subtraction of these numbers is : "+result);
	}
}

Sample Output

Output is 
num1=12; num2=8
The result after subtraction of these numbers is : 4