编译代码时,我一直无法获取double不能被取消引用的错误。这是我编写的通过2D数组解析的代码
/*
* calcCarbonFootprints
*
* Purpose: calculates carbon foot print of each person in a population
* and store the result in the corresponding index of the 1D result array
*
* Parameters: double[] - a 2D array of data for a populution where,
* each row represents an individual in the population and
* each column of a row has the following data for that individual:
* -fuel efficiency of their car
* -average kms driven per day
* -the age of their car
* -average kms on transit per day
* int[] - a 1D array to store the total carbon footprint for each individual
*
* Preconditions: none
*
* Returns: void
*
*/
// TODO
public static void calcCarbonFootprints ( double[] data, int[] carbon_footprint_results) {
for (int i=0; i < data.length; i++) {
for (int j=0; j<(int)data[i].length;j++) {
}
}
}
是因为我需要在第二个for循环中使用它之前将data[i]
转换为整数吗?
答案 0 :(得分:0)
正如@Gendarme所说,double
没有length
字段。在第二个循环中,您有data[i].length
应该抛出该错误。当您在数组中请求第i
个double
,然后询问编译器不喜欢的double
的{{1}}时。
您可以尝试取消length
现场通话。
答案 1 :(得分:0)
如果您尝试解析2D双精度数组,则函数isgnature应该为:
public static void calcCarbonFootprints(double[][] data, int[] carbon_footprint_results)