Advertisement
T0m

KHLeuven - Algo 2 - Recursievraag

T0m
Aug 31st, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         test n = new test();
  3.         String hello = "hello";
  4.         System.out.println("Resultaat: " + n.recursie(hello,hello.length()));
  5.     }
  6.    
  7.     public String recursie(String woord,int l)
  8.     {
  9.         System.out.println(woord + " " + l);
  10.         if(l > 1)
  11.         {  
  12.             woord = recursie(woord.substring(0,l-1) + "*" + woord.substring(l-1),l-1);
  13.         }
  14.        
  15.         return woord;
  16.     }
  17.  
  18. /*
  19. hell*o 4
  20. hel*l*o 3
  21. he*l*l*o 2
  22. h*e*l*l*o 1
  23. Resultaat: h*e*l*l*o
  24. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement