尝试从单独的runner程序中调用的.dat文件中提取等级值和名称值。在这个其他的java文件中的类是开始对我们来说,我们不得不“实例两个阵列...”和“使用一个for循环...”不兼容的类型int []不能转换为int错误
我得到一个错误
Incompatible types: int[] cannot be converted to int" error for "grades[i]=g;" and the corresponding String error for "names[i]=n;
想法?
public GradeBook(int[] g, String[] n, int num)
{
// **instantiate both arrays with 'num' objects
String []names=new String[num];
int[] grades=new int[num];
//**use a for-loop to assign each name and grade with the incoming values
for(int i=0;i<num;i++)
{
names[i]=n;
grades[i]=g;
}
}
请包括课程的完整代码。在这里我没有看到重复的地方,只是分配传入的数组并完成它。 –
也许你是指'names [i] = n [i]; 等级[i] = g [i];'虽然https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#copyOf(int[],%20int)将会是更好 –
@TimBiegeleisen'num'可能是与'n.length'不同的值 –