So I got an assignment, where the first problem is to set a minimum and maximum in an array which contains random numbers. I can figure out how to print the array with random numbers but I fail at setting said min/max. Classes im using: Random, Arrays, Scanner (which I need for the other problems of the assignment). I already tried searching for the same question but I only find the ones where they need help finding a min and max of an array.
thank you in advice.
my code:
public class Ex6 {
public static void main(String[] args) {
randomArray();
System.out.println(Arrays.toString(randomArray()));
}
public static int[] randomArray() {
int[] size = new int[10];
Random r = new Random();
/*I know this can be used to find the min and the max but not to set the min and max.
I just wrote it down to remind myself again*/
int min = Arrays.stream(size).min().getAsInt();
int max = Arrays.stream(size).min().getAsInt();
for (int i = 0; i < size.length; i++) {
size[i] = r.nextInt(100);
/*I also figured there may be a way working with r.nextInt(100) but I also can't really see the solution in front of me :/ */
}
return size;
}
}