![](/img/trans.png)
[英]i want to store multiple float values into array,retrieved from mysql database but it doesn't store all values
[英]I want to store N values into an array with the values filled sequentially starting from 1
我想生成 N 個整數值,其中N = row * column
(來自二維平面的一些坐標)到一個數組中。 然后我想從左到右依次將1到N的值分配到數組中,然后返回數組。
private static int[] to1Dcoords(int row, int column) {
grid = new int[row][column]; //creates n by n grid
int temp = 1;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[row].length; column++) {
grid[row][column] = temp;
temp++;
}
}
return grid;
}
這張圖片應該澄清我想要做什么
輸入到to1Dcoords(2,3)
輸出[1, 2, 3, 4, 5, 6]
如果您只想創建一個數組中數字遞增的一維數組,則可以在沒有中間二維數組的情況下執行此操作。
private static int[] to1Dcoords(int row, int column) {
int[] result = new int[row*column];
for (int i = 0; i < result.length; i++) {
result[i] = i;
}
return result;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.