两个数组:
String[] colrst={"NAME","YEAR","MONTH"};
String[][] result={{"name1","name2","name3"},{"2011Y","2012Y"},{"1M","2M","3M"}};
要得到:
NAME=name1 and YEAR=2011Y and MONTH=1M
NAME=name1 and YEAR=2011Y and MONTH=2M
NAME=name1 and YEAR=2011Y and MONTH=3M
NAME=name1 and YEAR=2012Y and MONTH=1M
NAME=name1 and YEAR=2012Y and MONTH=2M
NAME=name1 and YEAR=2012Y and MONTH=3M
NAME=name2 and YEAR=2011Y and MONTH=1M
NAME=name2 and YEAR=2011Y and MONTH=2M
NAME=name2 and YEAR=2011Y and MONTH=3M
NAME=name2 and YEAR=2012Y and MONTH=1M
NAME=name2 and YEAR=2012Y and MONTH=2M
NAME=name2 and YEAR=2012Y and MONTH=3M
NAME=name3 and YEAR=2011Y and MONTH=1M
NAME=name3 and YEAR=2011Y and MONTH=2M
NAME=name3 and YEAR=2011Y and MONTH=3M
NAME=name3 and YEAR=2012Y and MONTH=1M
NAME=name3 and YEAR=2012Y and MONTH=2M
NAME=name3 and YEAR=2012Y and MONTH=3M
请达人指点!lz,这是程序,请接收:
public class Test5 {
public static void main(String[] args) {
String[] colrst={"NAME","YEAR","MONTH"};
String[][] result={{"name1","name2","name3"},{"2011Y","2012Y"},{"1M","2M","3M"}};
for (int i = 0; i < result[0].length; i++) {
for (int j = 0; j < result[1].length; j++) {
for (int k = 0; k < result[2].length; k++) {
System.out.println(colrst[0]+"="+
result[0][i]+" and "+colrst[1]+"="+
result[1][j]+" and "+colrst[2]+"="+result[2][k]);
}
}
}
}
}
结果:
NAME=name1 and YEAR=2011Y and MONTH=1M
NAME=name1 and YEAR=2011Y and MONTH=2M
NAME=name1 and YEAR=2011Y and MONTH=3M
NAME=name1 and YEAR=2012Y and MONTH=1M
NAME=name1 and YEAR=2012Y and MONTH=2M
NAME=name1 and YEAR=2012Y and MONTH=3M
NAME=name2 and YEAR=2011Y and MONTH=1M
NAME=name2 and YEAR=2011Y and MONTH=2M
NAME=name2 and YEAR=2011Y and MONTH=3M
NAME=name2 and YEAR=2012Y and MONTH=1M
NAME=name2 and YEAR=2012Y and MONTH=2M
NAME=name2 and YEAR=2012Y and MONTH=3M
NAME=name3 and YEAR=2011Y and MONTH=1M
NAME=name3 and YEAR=2011Y and MONTH=2M
NAME=name3 and YEAR=2011Y and MONTH=3M
NAME=name3 and YEAR=2012Y and MONTH=1M
String[] colrst={"NAME","YEAR","MONTH"};
String[][] result={{"name1","name2","name3"},{"2011Y","2012Y"},{"1M","2M","3M"}};
String[] one=result[0];
String[] two=result[1];
String[] three=result[2];
for(int i=0;i<one.length;i++){
for(int j=0;j<two.length;j++){
for(int k=0;k<three.length;k++){
System.out.println(colrst[0]+"="+one[i]+" and "+colrst[1]+"="+two[j]+" and "+colrst[2]+"="+three[k]);
}
}
}