• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

公共类演示08 {

公共静态void main(String[] args) {

//创建一个10*10的二维数组,最终将该数组对应的稀疏数组打印出来

int[][]array 1=new int[10][10];

数组1[2][3]=2;

数组1[4][2]=13;

数组1[3][6]=25;

//将二维数组打印出来

for(int I=0;我数组1 .长度;i ) {

for(int j=0;j数组1.长度;j ) {

系统。出去。print(array 1[j]' ');

}

系统。出去。println();

}

//获取稀疏数组的有效值个数

int sum=0;

for(int I=0;我数组1 .长度;i ) {

for(int j=0;j数组1.长度;j ) {

if (array1[j]!=0) {

sum=1;

}

}

}

System.out.println('稀疏数组的有效个数总额值为sum);

//创建一个(总和1)*3的二维稀疏数组

//****注意:稀疏数组第一行是(10,10,3):10*10的数组对应稀疏数组的行数为3

int[][]array 2=new int[sum 1][3];

数组2[0][0]=10;

数组2[0][1]=10;

array 2[0][2]=sum;

int der=1;

for(int I=0;我数组1 .长度;i ) {

for(int j=0;j数组1.长度;j ) {

if (array1[j]!=0) {

数组2[der][0]=I;

array 2[der][1]=j;

数组2[der][2]=数组1[j];

引伸出(derive的缩写)

}

}

}

//打印稀疏数组

for(int I=0;I数组2。长度;i ) {

系统。出去。println(array 2[0]' ' array 2[1]

' ' array 2[2]);

}

//1.读取稀疏数组

//2.将稀疏数组还原

//按照稀疏数组第一行的对应行、列的值创建一个新数组数组3

int[][]array 3=new int[array 2[0][0]][array 2[0][1]];

for(int I=1;I数组2。长度;i ) {

数组3[数组2[0]][数组2[1]]=数组2[2];

}

//将还原的二维数组打印出来

//(数组的默认值是0)

for(int I=0;我发誓。长度;i ) {

for(int j=0;j数组3.长度;j ) {

系统。出去。print(array 3[j]' ');

}

系统。出去。println();

}

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now