Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required: Variable Found: Value

public static int biggestArrayGap(int []a, int n)
{
int biggestGap = Math.abs(a[1]-a[0]);
    for (int i=1; i<n-1; i++)
{
    if (Math.abs(a[i]-a[i-1]) > biggestGap)    
        Math.abs(a[i]-a[i-1]) = biggestGap;
}
    return biggestGap;
}

For some reason, the second line in the if statement is returning as unexpected type– required: variable found: value. I tried == and that obviously didn't work. Any insight?

like image 259
Alex Avatar asked May 10 '13 12:05

Alex


2 Answers

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.

like image 153
Sirko Avatar answered Nov 01 '22 16:11

Sirko


You have reversed your assign statement. Change it to

biggestGap = Math.abs(a[i]-a[i-1]);
like image 32
Keppil Avatar answered Nov 01 '22 15:11

Keppil