fork download
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. class Combinations {
  4.  
  5. public static void main(String[] args) {
  6. ArrayList<List<Character>> array = new ArrayList<List<Character>>();
  7.  
  8. ArrayList<Character> a1 = new ArrayList<Character>();
  9. ArrayList<Character> a2 = new ArrayList<Character>();
  10. ArrayList<Character> a3 = new ArrayList<Character>();
  11. a1.add('1');
  12. a1.add('2');
  13. a1.add('3');
  14.  
  15. a2.add('A');
  16. a2.add('B');
  17. a2.add('C');
  18.  
  19. a3.add('*');
  20. a3.add('#');
  21.  
  22. array.add(a1);
  23. array.add(a2);
  24. array.add(a3);
  25.  
  26. List<String> result = new ArrayList<String>();
  27. GeneratePermutations(array, result, 0, "");
  28.  
  29. for(String str : result) System.out.println(str);
  30. }
  31.  
  32. public static void GeneratePermutations(List<List<Character>> Lists, List<String> result, int depth, String current)
  33. {
  34. if(depth == Lists.size())
  35. {
  36. result.add(current);
  37. return;
  38. }
  39.  
  40. for(int i = 0; i < Lists.get(depth).size(); ++i)
  41. {
  42. GeneratePermutations(Lists, result, depth + 1, current + Lists.get(depth).get(i));
  43. }
  44. }
  45. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
1A*
1A#
1B*
1B#
1C*
1C#
2A*
2A#
2B*
2B#
2C*
2C#
3A*
3A#
3B*
3B#
3C*
3C#