Advertisement
leonardo_aly7

csr2

Jan 29th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1.  
  2. public class csr2{
  3.  
  4.    
  5.     //csr2:given a string S and an Integer n <= the length of S,
  6.     //generate all possible combinations of length n from the given string S.
  7.  
  8.     static String s ;
  9.     static char[] c ;
  10.     static int v ;
  11.    
  12.     public static void combinations(String s, int n){
  13.         csr2.s = s ;
  14.         c = new char[n];
  15.         v = 0;
  16.         comb(0,0);
  17.     }
  18.    
  19.     public static void comb(int n, int start){
  20.         if (n>=c.length){  
  21.             System.out.println(c);
  22.         }
  23.        
  24.         else for (int i = start; i < s.length(); i++) {
  25.             c[n] = s.charAt(i);
  26.             comb(n+1, i+1);
  27.         }
  28.     }
  29.    
  30.     public static void main(String[] args) {
  31.         combinations("abc",2);
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement