fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws java.lang.Exception {
  11. Ideone mainClass = new Ideone();
  12. Set<Integer> ints = new HashSet<Integer>();
  13.  
  14. ints.add(3);
  15. ints.add(5);
  16. ints.add(7);
  17.  
  18. ints = mainClass.recursiveSetCreator(ints);
  19.  
  20. printOutput(ints);
  21. }
  22.  
  23. private static void printOutput(Set<Integer> ints) {
  24. List list = new ArrayList(ints);
  25. Collections.sort(list);
  26. System.out.println(list);
  27. }
  28.  
  29. public Set<Integer> recursiveSetCreator(Set<Integer> recInput) {
  30. if (recInput.size() == 1) {
  31. return recInput;
  32. }
  33. List integerList = new ArrayList(recInput);
  34. Integer lastItem = (Integer) integerList.remove(integerList.size() - 1);
  35. recInput.remove(lastItem);
  36. recInput = recursiveSetCreator(recInput);
  37. int size = recInput.size();
  38. integerList = new ArrayList(recInput);
  39. for (int i = 0; i < size; i++) {
  40. Integer item = (Integer) integerList.get(i);
  41. recInput.add(item * lastItem);
  42. }
  43. recInput.add(lastItem);
  44. return recInput;
  45. }
  46. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
[3, 5, 7, 15, 21, 35, 105]