Java Reference
In-Depth Information
< Day Day Up >
Puzzle 65: A Strange Saga of a Suspicious Sort
This program sorts an array of randomly chosen Integer instances, using a custom comparator, and
then prints a word describing the order of the array. Recall that the Comparator interface has a
single method, compare , which returns a negative value if its first argument is less than its second,
zero if its two arguments are equal, and a positive value if its first argument is greater than its
second. This program is a showcase for release 5.0 features. It uses autoboxing and unboxing,
generics, and enum types. What does it print?
import java.util.*;
public class SuspiciousSort {
public static void main(String[] args) {
Random rnd = new Random();
Integer[] arr = new Integer[100];
for (int i = 0; i < arr.length; i++)
arr[i] = rnd.nextInt();
 
 
Search WWH ::




Custom Search