fork(3) 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. private static Stack<Integer> list = new Stack<Integer>();
  11. private static int n = 7;
  12.  
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. findSequence(3,1);
  16. }
  17. private static void findSequence(int k, int value){
  18. if(k==0){
  19. System.out.println(list.toString());
  20. return;
  21. }
  22.  
  23. for(int i = value; i <= n ; ++i){
  24. list.push(i);
  25. findSequence(k-1, i+1);
  26. list.pop();
  27. }
  28. }
  29. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
[1, 2, 3]
[1, 2, 4]
[1, 2, 5]
[1, 2, 6]
[1, 2, 7]
[1, 3, 4]
[1, 3, 5]
[1, 3, 6]
[1, 3, 7]
[1, 4, 5]
[1, 4, 6]
[1, 4, 7]
[1, 5, 6]
[1, 5, 7]
[1, 6, 7]
[2, 3, 4]
[2, 3, 5]
[2, 3, 6]
[2, 3, 7]
[2, 4, 5]
[2, 4, 6]
[2, 4, 7]
[2, 5, 6]
[2, 5, 7]
[2, 6, 7]
[3, 4, 5]
[3, 4, 6]
[3, 4, 7]
[3, 5, 6]
[3, 5, 7]
[3, 6, 7]
[4, 5, 6]
[4, 5, 7]
[4, 6, 7]
[5, 6, 7]