【发布时间】:2021-12-19 16:42:20
【问题描述】:
我有一个充满天气数据的double 二维数组。每行的格式相同,前两个数字是位置的经度和纬度,行的其余数字是该位置的实际天气数据。我应该如何查找特定行并仅将行的索引 1 之后的剩余数字复制到一维数组中(基本上忽略前两个索引)?
到目前为止我试过了:
int x = 0; //index for new 1d array
for(int i = 0; i <= weather.length; i++) {
for(int j = 0; j < weather[i].length; j++) {
//checks if this row's data is for the correct location
if(weather[i][j] == longitude && weather[i+1][j+1] == latitude) {
/* if the current element is the latitude, that means all of the values after the ith
index is the relevant data and can be copied into the new 1d array*/
data[x] = weather[i+1][j+1];
x++;
}
}
}
但这显然行不通。我似乎无法理解这样做的逻辑。如有任何反馈,我将不胜感激
【问题讨论】:
标签: java arrays multidimensional-array