/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { private static Stack<Integer> list = new Stack<Integer>(); private static int n = 7; { findSequence(3,1); } private static void findSequence(int k, int value){ if(k==0){ return; } for(int i = value; i <= n ; ++i){ list.push(i); findSequence(k-1, i+1); list.pop(); } } }
Standard input is empty
[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]