我想寫一個打印這些 號碼的所有可能安排一個遞歸方法,整數1至9如何找到所有可能的數字用遞歸方法
中的三行三列的網格隨機排列。例如:
6 2 1
5 4 7
3 9 8
對不起,我沒有任何代碼,因爲這對我很困難。
public class Test {
public static void main (String[] args){
String x = "123456789";
System.out.println(test(x,0));
}
public static String test(String x , int y){
if(x.length()==1)return "";
return x.charAt(y)+test(x.substring(y),y);
}
[算法找到下一個給定的字符串的更大排列]可能的重複(http://stackoverflow.com/questions/1622532/algorithm-to-find-next-greater-permutation-of-a-given-string ) – Prune
如果您搜索「Java陣列排列」,您會發現許多針對此問題的通用解決方案。 – Prune