Skip to content

Tag: java

What is the distribution of math.random in Java?

I want to use math.random() in a Java program. What is the distribution of this way of getting doubles? Answer This is documented in the Java SE API docs: public static double random() Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseud…

How to trigger a task after build

I have the following code: If I write build.doLast(generateJavaApi), IntelliJ tells me the following: No candidates found for method call build.dolast. Why is that and how would you trigger generateJavaApi after build? (so that running gradle build would automatically also trigger the generation of the java a…

Sort int[] array

I’m a bit confused on how to sort this array using the following conditions: int[] array = { 3, 15, 7, 11, 6, 4, 1, 8, 10, 13 }; The conditions are as follows: The largest integer is first The second-largest integer is last The third-largest integer should be second The pattern continues, leaving the sm…