Bootstrap

行,列优先存储

package Str;
public class Str_Chunchu {
	public static void main(String[] args) {
		int[][] data={{9,7,6,6},{1,2,1,4},{3,5,6,2},{2,3,3,2},{2,4,5,6}};
		int[] rowData=new int[20];
		int[] colData=new int[20];
		int i=0,j=0;
		System.out.println("输出二维数组");
		for(i=0;i<5;i++){
			for(j=0;j<4;j++){
				System.out.print(data[i][j]);
			}
			System.out.println("");
		}
		System.out.println("行优先存储");
		for(i=0;i<5;i++){
			for(j=0;j<4;j++){
				rowData[i*4+j]=data[i][j];
			}
		}
		System.out.println("列优先存储");
		for(i=0;i<5;i++){
			for(j=0;j<4;j++){
				colData[j*5+i]=data[i][j];
			}
		}
		System.out.println("输出行优先存储");
		i=0;
		while(i<rowData.length){
			System.out.print(rowData[i++]);
		}
		System.out.println("\n输出列优先存储");
		i=0;
		while(i<colData.length){
			System.out.print(colData[i++]);
		}
	}
}

 

;