必需:找到变量:值 [英] 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;
}
由于某种原因,if语句中的第二行作为意外类型返回 - required:找到的变量:value。我试过==这显然不起作用。有什么见解?
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?
推荐答案
你在你的赋值语句中切换了操作数。
You switched the operands in your assign statement.
切换此
Math.abs(a[i]-a[i-1]) = biggestGap;
到此
biggestGap = Math.abs(a[i]-a[i-1]);
Math.abs(a [i] -a [i-1] )
只返回一个int值(没有变量引用或类似)。因此,您尝试为值分配新值。这是不可能的。您只需为变量分配新值。
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.
这篇关于必需:找到变量:值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文