Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java: Write a JAVA program that reads a positive integer n (no less than 4) and produces 10 random permutations of the numbers 1
In Java:
Write a JAVA program that reads a positive integer n (no less than 4) and produces 10 random permutations of the numbers 1 to n. To generate a random permutation, you need to fill an array with the numbers 1 to n so that no two entries of the array have the same contents. You could do it by brute force, by calling Random.nextInt until it produces a value that is not yet in the array. Instead, in this lab assignment, you should implementa smart method. Make a second array and fill it with the numbers 1 to n. Then pick one of those at random, remove it, and append it to the permutation array You need to complete the implementation of classes PermutationGenerator and MyListoperations and use them in the main ) method. class PermutationGenerator int maxnum; / permutation is for numbers maxnum PermutationGenerator (int n) maxnum = n; // generate a random permutation of numbers 1maxnunm // return a permutation array which stores a random permutation int[l generate ( // array for a random permutation int permutation[] = new int [maxnum); // numbers not yet in a permutation int second [ ] = new int [maxnum); // your code comes hereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started