Possible loss of precision
Required: int; found: float
In the following code why does java give the error highlighting last line of the code instead of fourth line ?Do you know what an int is? Do you know what a float is? If not you would be wise at the point in time to go find that out. Then it will be easy for you to answer why you would get this "loss of precision" error. I will translate that error to something simpler: "You will lose stuff".
Now your question is valid and is a good one. Now line 4 is NOT highlighted but, like your code, line 5 is highlighted with a possible loss of precision.
int i = 0; float w = 3.14f; i += w; // line 4 i = i + w; // line 5 i = (int)(i + w); // line 6
As you now know they are NOT. But these two lines are:
i += w; // line 4 . . . i = i + w;
So for your question (using an initialized i to make that line valid)
i += w; // line 4 . . . i = (int)(i + w); // line 6