I am trying to program a Java Code in which, given the lenght of an int array and a min and max values it returns an random array values.
I am trying to program it in the most simple way, but I am still not getting how the programming process works.
What I have tried is the following:
import java.util.Random;
public class RandomIntArray {
public static void main(String[] args){
System.out.println(createRandom(10));
}
public static int[] createRandom(int n) {
Random rd = new Random();
int[] array = new int[n];
int min = 5;
int max = 99;
for (int i = 0; i < array.length; i++) {
array[i] = rd.nextInt();
while (array[i] > min) ;
while (array[i] < max) ;
}
return array;
}
}
Aucun commentaire:
Enregistrer un commentaire