日期:2014-05-20 浏览次数:20977 次
import java.util.ArrayList;
public class ArrayConvert1 {
ArrayList<String[][]> alist=new ArrayList<String[][]>();
public void conv(String[][] strArr){
int[] pos=new int[strArr.length];//保存需要复制的长度,0表示长度为1,依次类推。
while(pos[0]<strArr[0].length){
alist.add(createArray(strArr,pos));
addPos(strArr,pos);
}
}
public void addPos(String[][] strArr,int[] pos){
int pow=1;
for (int i = pos.length-1; pow > 0 && i > 0; i--) {
pos[i]=(pos[i]+pow)%strArr[i].length;
pow=pos[i]==0?1:0;
}
pos[0]+=pow;
}
public String[][] createArray(String[][] strArr,int[] pos){
String[][] newarr=new String[strArr.length][];
for(int j=0;j<strArr.length;j++){
String[] arr=new String[pos[j]+1];
System.arraycopy(strArr[j], 0, arr, 0, pos[j]+1);
newarr[j]=arr;
//输出结果数组
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
System.out.print(" | ");
}
System.out.println();
return newarr;
}
public static void main(String[] args) {
String[][] strArr = { { "00", "01" }, { "10", "11", "12" },{ "20", "21", "22" } };
new ArrayConvert1().conv(strArr);
}
}