Advertisement
remote87

MixString

Nov 14th, 2020
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         StringBuilder s1 = new StringBuilder("0123456789");
  8.         int length = s1.length();
  9.         String s2 = "";
  10.         int result = 0;
  11.  
  12.         Random r = new Random();
  13.  
  14.         for(int i = 0; i < length; i++){
  15.             result = (int)(r.nextDouble() * s1.length());
  16.             s2 += s1.charAt(result);
  17.             s1.delete(result, result + 1);
  18.         }
  19.         System.out.println(s2);
  20.     }
  21. }
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement