RageBin - Collaborative Raging

Ragebin is a collaborative Raging tool allowing you to share and modify rage snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a browser that supports this.

Java RageBin - Home - View Help - Archive - Ragers IRC - Image Boards

Posted by Anonymous on Wednesday 27th April 2011 08:27:03 - Never Expires
download | new post

  1. import java.util.Arrays;
  2. import java.util.Collections;
  3. import java.util.Iterator;
  4. import java.util.LinkedList;
  5. import java.util.Random;
  6. import javax.swing.JOptionsPane;
  7.  
  8. public class Main
  9. {
  10.   public static void main(String[] args)
  11.   {
  12.     int node = Integer.parseInt(JOptionPane().showInputDialog("Enter number of nodes:"));
  13.     if (node == 0)
  14.     {
  15.       System.out.println("You have not supplied a valid number, or have entered zero.");
  16.       return; // Why must we go on if there is no work?
  17.     }
  18.     LinkedList list = new LinkedList();
  19.     Random rand = new Random();
  20.    
  21.     // Fill the list with random values...
  22.     for (int i = 0; i < node; i++)
  23.     {
  24.       list.add(new Integer(rand.nextInt(150)));
  25.     }
  26.     int count, total, med, hi, low = 0, 0, 0, 0, 151;
  27.     Iterator iter = list.iterator();
  28.    
  29.     // Sort the list...
  30.     Collections.sort(list);
  31.    
  32.     // Calculate information based on the list...
  33.     while (iter.hasNext() == true)
  34.     {
  35.       count++;
  36.       Integer val = (Integer)iter.next();
  37.       total += val;
  38.       if (num < low) low = val;
  39.       if (num > hi) hi = val;
  40.       if (count == (node / 2)) med = val;
  41.      
  42.       System.out.println(count + "\t" + val);
  43.     }
  44.    
  45.     // Print out our results...
  46.     System.out.println("Total: " + total);
  47.     System.out.println("Mean: " + ((double)total / count));
  48.     System.out.println("Median: " + med);
  49.     System.out.println("Range: " + (hi - low));
  50.     System.out.println("You have " + count + " node(s)!");
  51.   }
  52. }

Submit a correction or amendment below. (click here to post a fresh rage)
After submitting an amendment, you'll be able to view the differences between the old and new rage easily.
Syntax Highlighting:
To highlight particular lines, prefix each line with @@
Pressing TAB inserts 3 spaces