Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. public class test
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         String s1 = "GATC";
  6.         System.out.println(s1);
  7.  
  8.         String s2 = shuffle(s1);
  9.         System.out.println(s2);
  10.     }
  11.  
  12.     public static String shuffle(String str)
  13.     {
  14.         if(str.length() <= 1)
  15.             return str;
  16.  
  17.         String tmp1 = shuffle(str.substring(0, (str.length()/2)));
  18.         String tmp2 = shuffle(str.substring(str.length()/2));
  19.  
  20.         if(Math.random() > 0.5)
  21.             return tmp1 + tmp2;
  22.         else
  23.             return tmp2 + tmp1;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement