特に意味は無いけど何重になるかわからない時使ってる
class AllNumber { public Integer min; public Integer max; public ArrayList<Integer> numbers; public int pattern(String str, int depth) { numbers = new ArrayList<>(); if (max == null) max = 9; if (min == null) min = 0; if (min > max) return -1;// 今回は面倒なので例外投げない return priPattern(str, depth); } private int priPattern(String str, int depth) { if(str==null)str=""; int count = 0; if (max == null) max = 9; if (min == null) min = 0; if (depth < 1) { numbers.add(Integer.valueOf(str)); } else { for (int i = min; i <= max; i++) { count += priPattern(str + String.valueOf(i), depth - 1); } } return count; } }