M
M
mxbk412022-02-01 20:55:42
Java
mxbk41, 2022-02-01 20:55:42

How to write a script in java?

In jmeter, it was necessary to write logic in java.
I have 5 numbers in a variable, it is necessary to always find the largest of 5 numbers and use it.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fadmin, 2022-03-11
@Fadmin

You can for example like this:

public static void main(String[] args) {
        Random r = new Random();
        int[] fiveRandomNumbers = r.ints(5, 0, 100).toArray();
        int item = Arrays.stream(fiveRandomNumbers).max().getAsInt();
        System.out.println(Arrays.stream(fiveRandomNumbers).boxed().collect(Collectors.toList()) +" - "+ item);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question