任何人都知道如何通过这样的用户输入组合: 用户选择了一些选项,如
Size:L,XL,XXL,... AND|OR
Color: red,green,black,... AND|OR
ANY_OTHER_OPTION : VALUE_1,VALUE_2,...
大小我什么都不是,还有其他选择
我需要输出像
L.red.VALUE_1
L.red.VALUE_2
L.green.VALUE_1
L.green.VALUE_2
L.black.VALUE_1
L.black.VALUE_2
XL.red.VALUE_1
XL.red.VALUE_2
XL.green.VALUE_1
XL.green.VALUE_2
XL.black.VALUE_1
XL.black.VALUE_2
XXL.red.VALUE_1
XXL.red.VALUE_2
XXL.green.VALUE_1
XXL.green.VALUE_2
XXL.black.VALUE_1
XXL.black.VALUE_2
该组合的最佳做法是什么?
答案 0 :(得分:0)
假设选项存储在数组中,这里是您想要的代码:
String[] sizes = {"L", "XL", "XXL"};
String[] colors = {"red", "green", "black"};
String[] others = {"VALUE_1", "VALUE_2"};
for (int i=0; i < sizes.length; i++){
for (int j=0; j < colors.length; j++){
for (int k=0; k < others.length; k++){
System.out.println(sizes[i] + "." + colors[j] + "." + others[k]);
}
}
}