java – Required: Variable Found: Value

java – Required: Variable Found: Value

You switched the operands in your assign statement.

Switch this

Math.abs(a[i]-a[i-1]) = biggestGap;

to this

biggestGap = Math.abs(a[i]-a[i-1]);

Math.abs(a[i]-a[i-1]) returns just an int value (no variable reference or similar). So your trying to assign a new value to a value. Which is not possible. You can just assign a new value to a variable.

You have reversed your assign statement. Change it to

biggestGap = Math.abs(a[i]-a[i-1]);

java – Required: Variable Found: Value

You are trying to assign the value of biggestGap to the number returned by Math.abs(). Naturally, you cant, because that value depends on what Math.abs() contains and how it handles its arguments.

Perhaps you meant the opposite:

biggestGap = Math.abs(a[i]-a[i-1]);

Leave a Reply

Your email address will not be published.