Java - Operator Subtraction Operator -

What is Subtraction Operator?

The subtraction operator (-) is used in the form

operand1 - operand2 
  

The subtraction operator calculates the difference of two numbers.

The following are some examples of using the subtraction operator:

Subtraction Operator Promotion

b1 = 17 is ok, because 17 is in the range -128 and 127

byte b1 = 5; 
b1 = 190 - 173; // Ok.
      

i - 27 is of the type int. int to byte assignment is not allowed

int i = 100;   
byte b1 = 5; 
  
b1 = i - 27; // An error.

You can add cast to fix the error.

double d1 = 15.45; 
byte b1 = (byte)(d1 -27);  // OK