Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class csr2{
- //csr2:given a string S and an Integer n <= the length of S,
- //generate all possible combinations of length n from the given string S.
- static String s ;
- static char[] c ;
- static int v ;
- public static void combinations(String s, int n){
- csr2.s = s ;
- c = new char[n];
- v = 0;
- comb(0,0);
- }
- public static void comb(int n, int start){
- if (n>=c.length){
- System.out.println(c);
- }
- else for (int i = start; i < s.length(); i++) {
- c[n] = s.charAt(i);
- comb(n+1, i+1);
- }
- }
- public static void main(String[] args) {
- combinations("abc",2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement