import java.io.*; class combination { public static void main(String args[])throws IOException { DataInputStream in; String s; int a,n,r; System.out.print("Enter the value of n : "); in = new DataInputStream(System.in); s = in.readLine(); n = Integer.parseInt(s); System.out.print("Enter the value of r : "); in = new DataInputStream(System.in); s = in.readLine(); r = Integer.parseInt(s); if(n < r) System.out.println("\n\t\tCheck the input.\n"); else { int i,j; String v[] = new String[n]; System.out.println("Enter the n's : "); for(i = 0; i < n; i++) { in = new DataInputStream(System.in); s = in.readLine(); v[i] = s; } int temp[] = new int[r], q; boolean f = false; for(i = 0; i < r; i++) temp[i] = i; System.out.println("\nThe Combinations are :\n"); a = 1; while(temp[0] <= n - r) { while( temp[r - 1] < n ) { for(j = 0; j < r; j++) System.out.print(" " + v[ temp[j] ] + ","); System.out.print(" - " + a++); in.readLine(); temp[r - 1] += 1; } for(j = r - 1, i = 0, f = false; j > 0 && f == false; i++,j--) if(temp[j] <= n) f = true; for(i = j, q = temp[j]; i < r; i++) temp[i] = q + i - j + 1; } } } }