输入n(1 < n < 5)个m(0<m<100), 按顺序打印它们组成的所有数字
(如果输入非法, 提示用户重新输入)
截图要求提供输入非法m值的运行结果(字符/超范围数字)
样例输入: 5 20 3
样例输出: 2035 2053 3205 3520 5203 5320
è¿ä¸ªå¯ä»¥åæéå½ä¹å¯ä»¥åæééå½ï¼éå½åèµ·æ¥ç®åï¼å°±ç¨éå½çç»ä½ ä¾åï¼
代ç å¦ä¸ï¼
public class SimpleCodeTest {
public static void DFS(List<Integer> candidate, String prefix, int showLength) {
if (prefix.length() != 0 && prefix.length() == showLength) {
System.out.println(prefix);
}
for (int i = 0; i < candidate.size(); i++) {
List<Integer> temp = new LinkedList<Integer>(candidate);
int item = (int) temp.remove(i); // ååºè¢«å é¤çå ç´ ï¼è¿ä¸ªå ç´ å½åä¸ä¸ªç»åç¨æäº
DFS(temp, prefix + item, showLength);
}
}
public static void main(String[] args) {
Integer[] array = { 1, 2, 0, 9 };
List<Integer> list = Arrays.asList(array);
DFS(list, "", list.size());
}
}
è¿è¡å¾å¦ä¸ï¼