0

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;
    }
}
  • What does "Set a minimum and maximum int in a random number array" even mean in your case? Set where? Do you mean you want to sort the array? Does that mean you want your random generated numbers to be in the range of min-max? – OH GOD SPIDERS Nov 15 '22 at 10:19
  • @OHGODSPIDERS it means that the array prints random numbers which have to be bigger than lets say 5 and smaller than 100. – meltdown543 Nov 15 '22 at 10:24

0 Answers0