import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.Random; import javax.swing.JOptionsPane; public class Main { public static void main(String[] args) { int node = Integer.parseInt(JOptionPane().showInputDialog("Enter number of nodes:")); if (node == 0) { System.out.println("You have not supplied a valid number, or have entered zero."); return; // Why must we go on if there is no work? } LinkedList list = new LinkedList(); Random rand = new Random(); // Fill the list with random values... for (int i = 0; i < node; i++) { list.add(new Integer(rand.nextInt(150))); } int count, total, med, hi, low = 0, 0, 0, 0, 151; Iterator iter = list.iterator(); // Sort the list... Collections.sort(list); // Calculate information based on the list... while (iter.hasNext() == true) { count++; Integer val = (Integer)iter.next(); total += val; if (num < low) low = val; if (num > hi) hi = val; if (count == (node / 2)) med = val; System.out.println(count + "\t" + val); } // Print out our results... System.out.println("Total: " + total); System.out.println("Mean: " + ((double)total / count)); System.out.println("Median: " + med); System.out.println("Range: " + (hi - low)); System.out.println("You have " + count + " node(s)!"); } }