Question: import java.util.Random; public class RandomUnique { public static void main(String[] args) { int n = 5; int[] values = generateRandomUnique(n); boolean valid = true; for(int
import java.util.Random;
public class RandomUnique { public static void main(String[] args) { int n = 5; int[] values = generateRandomUnique(n); boolean valid = true; for(int i =0; i < values.length; i++) { for(int j = i+1; j < values.length; j++) { if(values[i] == values[j]) { System.out.print("Error: The values are not unique: "); valid = false; break; } } } if(valid) System.out.print("Successful, the values are: "); for(int i = 0; i < values.length; i++) { System.out.print(values[i] + " "); } } public static int[] generateRandomUnique(int n) { Random random = new Random(); /*FIXME Complete this method*/ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
