代码如下:
public class TestArray {
public static void main(String[] args){
TestArray ta = new TestArray();
int arrayLength = 5;
String arrayB[][] = {{"1","0","1"},{"1","1","1"},{"0","0","1"},{"1","0","0"},{"1","1","0"}};
String arrayA[][] = ta.getResult( arrayB, 2);
}
private String[][] getResult(String[][] arrayB, int l){
if(l<0) return null;
String arrayA[][] = new String[arrayB.length][arrayB[0].length+l];
for(int i=0; i
arrayA[i][j] = arrayB[i][j];
}else{
arrayA[i][j] = this.calculator(arrayA[i][j-3], arrayA[i][j-2], arrayA[i][j-1]);
}
System.out.print("["+arrayA[i][j]+"]");
if(j == arrayA[0].length -1){
System.out.println("|");
}else{
System.out.print(",");
}
}
}
return arrayA;
}
//用于根据数组前三位
private String calculator( String i, String j, String k){
String result = "x";
if("0".equals(k)||"0".equals(j)){
return "1";
}else if("1".equals(k)&&"1".equals(j)&&"1".equals(i)){
return "0";
}
return result;
}
}
输出结果:
[1],[0],[1],[1],[x]|
[1],[1],[1],[0],[1]|
[0],[0],[1],[1],[x]|
[1],[0],[0],[1],[1]|
[1],[1],[0],[1],[1]|
这么复杂.
太长没看.......