randomly generates 3 67~295 integers and finds the number centered and outputs the middle number
Example: 100,225 and 200, output
To randomly produce integers in a range, the nextint (int num) of the Java.util.Random class is the most concise.
nextint (int num) can accept an integer as the upper bound of the random integer it produces, with a lower bound of zero, such as:
Nextint (4) will produce 0,1,2,3 any one of the 4 numbers, note that this is not 0-4, but 0-3.
。 But the lower bound is always zero and cannot be changed, so to achieve the effect of a non-0 lower limit, the upper limit minus the lower bound result must be passed to Nextint (), and then the lower bound is added to the integer returned by Nextint ().
The number of random numbers is collected in the array, and then the array is sorted with the same arrays.sort () in the Java.util packet, and the center count is in the immediate place.
1Import java.util.*;2 3 classC {4 Public Static voidMain (string[] args) {5 6Random Rand =NewRandom ();7 int[] Trio =New int[3 ];8 9System. out. println ("three random integers in the range of [295]:" );Ten for(inti =0; I <3; ++i) { Onetrio[i] = Rand.nextint (295- the) + the; ASystem. out. println (trio[i]); - } - the Arrays.sort (trio); - -System. out. println ("\nmedian:\n"+ trio[1 ] ); - } +}
nextint (int num) of the Java.util.Random class