short s1 = 4500, s2 = 9800;
short s3;
s3 = s2 - s1;
System.out.println("The difference is:- " + s3);
I ran this code and it is showing an error but work perfectly when I declare s3 as int. Why is this happening? The error it is showing is as follows :- ''' Main.java:15: error: incompatible types: possible lossy conversion from int to short s3 = s2 - s1; ^ 1 error '''
I tried running the code and I thought the code would run. But in mathematical operations it shows error and suggests that instead of short, byte variable use int variable.