gpt4 book ai didi

java - 如何将二维数组拆分为左右数组?

转载 作者:行者123 更新时间:2023-11-29 05:52:17 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
java: How to split a 2d array into two 2d arrays

需要的是拆分这个数组:

int[][] bitblock = {
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0}};

这是一个8*8的数组,我想把它拆分成左右数组存在这里:

int[][] leftblock = new int [bitblock.length][bitblock[0].length/2];
int[][] rightblock = new int [bitblock.length][bitblock[0].length/2];

我使用了 Syste.arraycopy 方法,我能够将位 block 拆分为上下数组,我有点难以左右拆分它:

System.arraycopy(bitblock, 0, leftblock, 0, leftblock.length);
System.arraycopy(bitblock, rightblock.length, rightblock, 0, rightblock.length)

有人可以帮忙吗?谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com