Guest User

Untitled

a guest
Oct 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class MakeBigArrayPerm
  4. {
  5.     public static void main(String[] args) throws IOException
  6.     {
  7.         Random r = new Random();
  8.     final int ARRAY_SIZE = 20;
  9.         int [] nums1 = new int [ARRAY_SIZE];
  10.     int [] nums2 = new int [ARRAY_SIZE];
  11.    
  12.     File outFile = new File ("output.txt");
  13.     FileWriter fw = new FileWriter (outFile);
  14.     PrintWriter pw = new PrintWriter (fw);
  15.    
  16.     //fill
  17.     for(int i = 0; i < ARRAY_SIZE; i++)
  18.         {
  19.             nums1[i] = r.nextInt(9999999);
  20.       pw.print(nums1[i] + ", ");
  21.         }
  22.     pw.println();
  23.     //copy
  24.     for(int i = 0; i < ARRAY_SIZE; i++)
  25.     {
  26.       nums2[i] = nums1[i];
  27.     }
  28.         //shuffle
  29.         for (int i = 0; i < ARRAY_SIZE; i++)
  30.     {
  31.       int rIdx = r.nextInt(ARRAY_SIZE);
  32.       int temp = nums2[i];
  33.       nums2[i] = nums2[rIdx];
  34.       nums2[rIdx] = temp;
  35.     }
  36.     for(int i = 0; i < ARRAY_SIZE; i++)
  37.     {
  38.       pw.print(nums2[i] + ", ");
  39.     }
  40.     pw.close();
  41.     }
  42. }
Add Comment
Please, Sign In to add comment