【发布时间】:2016-06-25 16:34:28
【问题描述】:
I have the following error in compiler
return ans;
^
required: byte[]
found: int[]
我有这种方法,我想在其中返回一种字节。谁能告诉我如何转换 ans 以使其与我的方法类型兼容
public byte[] element(int m) {
//if (q!= a.length)
// throw new Exception("Array length does not equal k");
int f;
int q;
int[] t;
this.first = f;
this.second = q;
this.data = new int[q];
for (int i = 0; i < t.length; ++i) {
this.data[i] = t[i];
}
// if (!this.IsValid())
// throw new Exception("Bad value from array");
int ans[] = new int[this.second];
int a = this.first;
int b = this.second;
int x = (choose(this.first,this.second) - 1) - m; // x is the "dual" of m
for (int i = 0; i < this.second; ++i) {
ans[i] = largestV(a, b, x); // largest value v, where v < a and vCb < x
x = x - choose(ans[i], b);
a = ans[i];
b = b - 1;
}
for (int i = 0; i < this.second; ++i) {
ans[i] = (first-1) - ans[i];
return ans;
}
}
注意:我希望它返回字节类型而不是 int,但我正在尝试转换 ans 但没有成功。
【问题讨论】:
-
如果你想要一个字节[],为什么要将它创建为一个int[]?只需将其创建为一个字节,然后在赋值“ans[i] = (byte) maximumV(...)”中进行转换。