equivalenceClasses method given in
Program 12.25.
The source code for the main method is available here.
The input is a sequence of integers. The first integer specifies the size of the universe of the partition. The remainder of the input consists of pairs of integers. As each pair of integers (i,j) is entered, the application performs a join operation to join the elements of the partition containing i and j. After all the join operations have been performed, the application prints the resulting partition.