How should I correct my code to find the mean, median & mode from an array?

Hello everyone,
I have been learning Java for about a month now and am stuck with the following code. There are no highlighted errors on my program when typing it into Eclipse but I get an error message when I try to run my program.
Here is the code:
import java.util.Random;
* <dl>
* <dt>Purpose:
* <dd>Example program that randomly generates, collates and outputs numbers.
* <dt>Description:
* <dd>This program generates 10000 random numbers between 0 and 99 inclusive.
* It also keeps count of how many times each number is generated and prints these
* counts out to the screen in the format of mean, median and mode.
* </dl> 
* @author  Woodie Woodpeck
* @version $Date: 2008/10/27 14:44:00 $
public class Exercise3Point08
     public static void main(String[] args)
               int[] counts=new int [100];
               for(int i=0;i<100;i++)
                    counts=0;
               Random r=new Random();
               for(int n=0;n<10000;n++)
                    counts[r.nextInt()%100]++;
               double sum=0.0;
               int maxCnt=0;
               int mode = 0;
               int runningCount=0;
               int median = 0;
               for (int i=0;i<100;i++)
                    sum+=(i*counts[i]);
                    if (counts[i]>maxCnt)
                         mode=i;
                         maxCnt=counts[i];
                    if (runningCount<5000&&(runningCount+counts[i])>=5000)
                         median=i;
                    runningCount+=counts[i];
               System.out.println("Mean =" + (sum/10000));
               System.out.println("Median =" + median);
               System.out.println("Mode =" + mode);
Here is my error message:Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
     at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
And that's it. Hmmmm. Strange. I hope someone can help.
Many Thanks
Wood                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Hi Edward,
I moved the file from my college computer to my home computer using a USB stick and changed the workspace path on my Eclipse software to match the files that I transferred. I also cleared out a lot of random code that I had lying around my hard-drive before trying to use the code that I pasted above.
From reading the output I guess there is a problem with the class. Do you think I might have transferred the file from one computer to another incorrectly? Do you know how I can clean and rebuild a project? Eclipse seems quite daunting and awfully complicated for a beginner!
Thanks
Wood

Similar Messages

  • How do I correct error code 150.30?

    When I tried to start Photoshop Elements 8, I received error code 150.30.  I was instructed to restart my computer.  I did this, but the error code persisted.  It then said to contact Adobe.  I used this software about a couple of months ago and it was fine.  Any suggestions?

    I tried to follow the instructions, but when I downloaded the winzip 
    program I got a box that stated I needed another program called python25.dll, 
    which appeared as a sales tool, so I stopped.  Can I just remove the 
    Photoshop Elements 8 software and reinstall it to fix the problem?
    Russ
    In a message dated 12/25/2013 3:08:11 P.M. Eastern Standard Time, 
    [email protected] writes:
    Re:  How do I correct error code 150.30?
    created by LittlePale_Face_
    (http://forums.adobe.com/people/Little_Pale_Face)   in Photoshop Elements - View the full  discussion
    (http://forums.adobe.com/message/5956433#5956433)

  • How do I correct error code U43M1D207 Illustrator CS5

    I am notified of updates for Fireworks CS5, Photoshop Elements 9.0.1, Illustrator CS5, Adobe Pixel Bender toolkit 2.5, Adobe Extension Manager CS5.  When I try to get the downloads I continue to get an Error Code U43M1D207.  How do I overcome this error code?

    I tried to follow the instructions, but when I downloaded the winzip 
    program I got a box that stated I needed another program called python25.dll, 
    which appeared as a sales tool, so I stopped.  Can I just remove the 
    Photoshop Elements 8 software and reinstall it to fix the problem?
    Russ
    In a message dated 12/25/2013 3:08:11 P.M. Eastern Standard Time, 
    [email protected] writes:
    Re:  How do I correct error code 150.30?
    created by LittlePale_Face_
    (http://forums.adobe.com/people/Little_Pale_Face)   in Photoshop Elements - View the full  discussion
    (http://forums.adobe.com/message/5956433#5956433)

  • How should I correctly close runtime datasource?

    I'm using CR4J API from web application, java.sql.ResultSet is used as runtime DataSource for report. The question is: how should I correctly close this ResultSet? As far as I understand ResultSet have to be opened up to JSP rendering phase and while report is used on client (moving between pages, etc), otherwise Exception would be thrown. The problem is: when user tries to run this report again, corresponding records in database are locked, so ResultSet and probably Connection have to be closed before subsequent report request. How can I do that correctly?
    P.S. I'm cleaning the report source as Ted Ueda's article "Ensuring Report Cleanup" describes.

    Hmmm... my knowledge of CR4J is limited , but just thinking about it, I might dump your ResultSet into a CachedRowSet so you can post-process fully disconnected.
    http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html
    good luck

  • How do I get my ipad to find the wireless HP printer that is supposed to be compatible w/ Air Print

    How do I get my ipad to find the wireless HP printer that is supposed to be compatible w/ Air Print?

    Mary-
    First be sure your printer is on Apple's list of AirPrint compatible printers at <iOS: AirPrint 101>.
    Assuming it is on that list, check to see if there is a firmware update for it.  You should be able check it from the printer's control panel in one of the setup or preferences menus.
    If the printer is still not found in the iPad's print routine, your WiFi router may not correctly handle Bonjour data required by AirPrint.  You would need to contact the router's manufacturer to see if there is a change you can make to its setup, or if there is a firmware update that will solve the problem.
    Fred

  • How do i fix error code 6A00 on the LCD screen of my Canon PIXMA MP810

    how do i fix error code 6A00 on the LCD screen of my Canon PIXMA MP810 

    Hello drews,
    To try and resolve the 6A00 error, we will want to ensure that no paper jams or obstructions exist in the printer.  To do this, please follow the steps below:
    ASF / Paper Output Slot
    Turn off the printer.
    Remove paper from the ASF.
    Gently pull the jammed paper out.
    If paper is visible from the ASF, use both hands to pull the paper out slowly.
    If paper is visible from the paper output slot, use both hands to pull the paper out slowly.
    If the paper tears and a piece of that remains inside the printer, open the scanning unit (printer cover) and remove the paper from inside the printer.
    Note : Be careful not to touch the components inside the printer.
    Turn on the printer and confirm that the Alarm light is off.
    (If the jammed paper remains in the printer, the paper may be automatically ejected.)
    Load paper back into the ASF.
    Press <OK> to clear the message and continue printing. If you are printing from an application software, follow the instructions displayed on your computer.
    Top
    Paper jams inside the printer
    Turn off the printer and disconnect the power cord and USB cable.
    Remove the jammed paper slowly using the following procedure.
    Open the rear cover to check if the paper is jammed.
    Pull out the cassette and check if the paper is jammed inside the cassette area.
    Stand the printer with the rear side down, holding the document cover.
    Press the tabs together and pull the green cover toward you.
    Check if the paper is jammed.
    (If you were not doing Duplex printing, you do not have to follow this procedure.)
    Close the green cover and place the printer back to a normal position.
    Reconnect the power cord and power on the printer. Confirm the Alarm light is off.
    Load paper back into the ASF or cassette.
    Press <OK> to clear the message and continue printing. If you are printing from an application software, follow the instructions displayed on your computer.
    Top
    Clearing credit card-sized paper jammed inside the printer
    Credit card-sized and 4" x 6" sized paper must be loaded properly. If this media is not loaded properly, it will feed into the printer and will not exit. Credit card-sized paper should only be loaded in the ASF and in portrait orientation. 4" x 6" sized paper can be loaded in the ASF or cassette. But must be loaded portrait orientation.
    If credit card-sized paper was loaded in landscape orientation in the ASF and did not eject (exit), please follow this procedure.
    Turn off the printer.
    Load the same paper type that is jammed inside the printer in portrait orientation.
    Power on the printer.
    The paper stock in the ASF will automatically feed the jammed paper from the printer.
    To resume printing, load the paper in portrait orientation.
    If 4" x 6" sized paper was loaded in landscape orientation in the cassette and did not eject (exit), please follow this procedure.
    Turn off the printer.
    Open the rear cover.
    Fold in four a piece of letter-sized plain paper.
    Push in the folded paper until it hits the jammed paper.
    If the jammed paper is visible from inside the printer area, pull it out and proceed to step 7.
    If the jammed paper cannot be pulled out, push in the folder paper from the rear so the jammed paper is in between the feed rollers.
    Pull out the folded paper and close the rear cover.
    Power on the printer and confirm that the Alarm light is off.  The jammed paper should automatically eject.
    To resume printing, load the paper in portrait orientation.
    If you still experience the same error after performing the steps above, please turn off the printer, unplug the power cord from the back and leave it out for at least 10 minutes, then plug it back in and turn it back on.  If the error persists, unfortunately, the printer will require servicing to resolve the issue.  Please click on the Contact Us link below to obtain your servicing options.
    This didn't answer your question or issue? Find more help at Contact Us.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • How do i find the music i sync from my ipad to imac

    how do i find the music i sync from my ipad to imac

    How did you sync the music from the iPad to the iMac? Did you plug the iPad in and choose File -> Transfer Purchases from <name of iPad> in iTunes?
    B-rock

  • How to use my findTheHighest method to find the highest value in my two dim

    I am going to create a 13row by 10 colume two dimensional array.
    how to use my findTheHighest method to find the highest value in my two dimensional array.
    .When i compile this program , i got those as following;
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
    at TaxEvolution.findTheHighest(TaxEvolution.java:31)
    at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
    public class TaxEvolution{
    public double[][] salesTaxRates;
    public TaxEvolution()
      salesTaxRates = new double[13][10];
      fillProvinTaxRates();
    private void fillProvinTaxRates()
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
    public double findTheHighest()
        double highest = salesTaxRates[0][0];
        for ( int row = 0; row <= salesTaxRates.length; row++ )
          for ( int column = 0; column <= salesTaxRates[row].length; column++ )
             if ( salesTaxRates[row][column] >= highest )
                   highest = salesTaxRates[row][column];
        return highest;   
    public double[][] arrayTaxEvolution()
      double[][] returnTaxRates = new double[13][10];
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          returnTaxRates = salesTaxRates;
      return returnTaxRates;
    public class TaxEvolutionClient{
    public static void main( String[] args ){
      TaxEvolution protaxRateList = new TaxEvolution();
      double[][] taxRateList = protaxRateList.arrayTaxEvolution();
        for ( int i = 0; i < taxRateList.length; i++ )
          for ( int j = 0; j < taxRateList[0].length; j++ )
            System.out.print( taxRateList[i][j] + "\t" );               
            System.out.print( protaxRateList.findTheHighest + "\t" );
    }

    Multiposted
    http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0

  • HT1711 how do I find the top 5 songs from a single artist!!

    How do I find the top 5 songs from a single artist?

    If you have unchecked the compilation tag on the CD tracks before you ripped them, then what you are describing shouldn't be happening. Are you sure you are unchecking the compilation tag for all of the tracks on the CD before you rip them?
    Unfortunately, you cannot change the default directory structure that iTunes rips albums into. You can feel free to move files after they are ripped, but iTunes will always rip them into its Artist/Album/Track #_Track Name format.

  • How to find the third highest salary from deptno20,from employee table

    how to find the third highest salary from deptno20,from employee table

    SELECT *
      FROM emp;
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO
    7369
    SMITH
    CLERK
    7902
    12/17/1980
    1000
    3
    20
    7499
    FEDERAL
    SALESMAN
    7654
    2/20/1981
    2000
    4
    30
    7521
    WARD
    SALESMAN
    7698
    2/22/1981
    3000
    4
    30
    7566
    JONES
    MANAGER
    7839
    4/2/1981
    4000
    3
    20
    7839
    MARTIN
    SALESMAN
    7698
    9/28/1981
    5421
    4
    30
    7698
    BLAKE
    MANAGER
    7698
    5/1/1981
    6222
    4
    30
    7782
    CLARK
    MANAGER
    7839
    6/9/1981
    5222
    2
    10
    7788
    SCOTT
    ANALYST
    7566
    12/9/1982
    5463
    3
    20
    7839
    KING
    PRESIDENT
    7902
    11/17/1981
    8543
    2
    10
    7844
    TURNER
    SALESMAN
    7698
    9/8/1981
    2124
    4
    30
    7876
    ADAMS
    CLERK
    7788
    1/12/1983
    2125
    3
    20
    7900
    JAMES
    CLERK
    7698
    12/3/1981
    5462
    4
    30
    7902
    FORD
    ANALYST
    7566
    12/3/1981
    2132
    3
    20
    7934
    MILLER
    CLERK
    7782
    1/23/1982
    5165
    2
    10
    SELECT sal, deptno
      FROM (SELECT   a.*,
                     DENSE_RANK () OVER (PARTITION BY deptno ORDER BY sal DESC) r
                FROM emp a
          ----  ORDER BY sal DESC
    WHERE r = 3;
    SAL
    DEPTNO
    5421
    30
    5165
    10
    2132
    20
    Regards ,
    Friend
    Message was edited by: MostWanted!!!!

  • I'm having issues with my gmail accounts in Mail since I upgraded to OS X Mavericks. All the mails start downloading again! How do I correct this so that only the new mails in these accounts get downloaded?

    I'm having issues with my gmail accounts in Mail since I upgraded to OS X Mavericks. All the mails start downloading again! How do I correct this so that only the new mails in these accounts get downloaded?

    I'm having issues with my gmail accounts in Mail since I upgraded to OS X Mavericks. All the mails start downloading again! How do I correct this so that only the new mails in these accounts get downloaded?

  • How to find the file that delete from time capsule?

    How to find the file that delete from time capsule?

    I mean I saved JPEG file in Time capsule and unfortunately delete the file. Can I get it back
    IF.... .no other backups have occured since you deleted the file, you might be able to retrieve it using an application like Disk Warrior. It's about $100 as I recall, and there are no guarantees that it will work.
    DiskWarrior 4 - The Disk Utility for Mac  Disk Repair, Mac Directory ...
    Any of the free or low priced utilities that you might see or try will not be able to retrieve a deleted file from a Time Capsule.
    If any backups have occured since you deleted the file, the deleted file has almost certainly been overwritten. No way to retrieve it in that case.

  • How do I find the music I uploaded from a cd

    Ever since I downloaded the update for itunes i can't find the music I uploaded from a cd...help

    Backup drive?
    Subscribe to iTunes Match?
    If neither of the above and you don't have the CD and can't find your tracks on the computer then they you're stuck.  A file recovery utility will cost $100, plus another $100 for an external drive to which to resue the files, and may not even work.  You can buy a lot of CDs for $200.

  • Finding the 25th largest number in an array

    How would I say find the 25th largest number in an array?
    Or nth largest number?
    Chris

    I find most of these answers correct, but without previous knowledge of the size of the array, I would do things differently.
    In the enclosed VI, a cluster is formed of all array values and their index. When the array is then sorted, the first cluster element is used as the first sort criterium, then the second cluster element. This allows a single array operation (Sorting) to take care of any searching, whilst the cluster retains the index of the original array.
    Coupling this method with an unitialised shift register, you can also cache the sorted array to allow for more rapid processing if you require more than a single indexed value.
    Another way to achieve this is (Assuming you`re seeking the 25 largest) to simply get the max and min at t
    he very beginning, feed the array into a loop with a shift register, set the value at the index returned for max each run to the initial min value -1, and repeat another 24 times.
    Regarding memory use and execution speed, I`m not sure if searching an array 25 times is quicker than a single sort or not (No new array is created), but both versions are viable.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
    Attachments:
    Get_Nth_largest-smallest_(6.1).vi ‏31 KB
    Get_Nth_largest-smallest_(6.1)_-_version_2.vi ‏42 KB

  • Finding the first maximum in a 1D array

    Hello evryone!!
    I have a huge 1D array and It has certain values which are like peaks when plotted. For example, the array may look like:
    1 0.23 0.12 0.34 0.2 1.345 0.25 0.13 0.45 0.16 1.023 ---- As you can notice, the array has maximum values  (magnitude close to 1) placed regularly. Now I need to find each of these maximum value and put them in an array. Currently I just start at iteration 0 of the array and use the array index function to get all of these peaks.
    However,in this code, I assume that the first maximum peak occurs at element 0 (first iteration) of array. But this may not be the case and the array might look like:
    0.23 0.12 1 0.24 0.34 0.15 0.19 1.023 0.45 0.51 0.21 0.3 1.345....etc. that is the first maximum value may not occur at the element 0 of the array. So the problem here is to find this first maximum peak and then as the others are placed at regular intervals, i can find them.
    Could any one please suggest as to how i could change my code to find this first maximum/peak. thanks for the help  

    LSASS wrote: 
    You may not have observed their regular appearance becuse the peaks are seperated by 584 values which is huge.
    I could not observe anything, because the original VI had no data at all and was not executable because of missing subVIs!
    Why don't you simply get the index of the first element that is above e.g. 0.5 as in the attached quick draft (LV 8.6)? Modify as needed.
    (I also did some general cleanup, your code was way too complicated, e.g. way too many loops! )
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    receiver_constMOD.vi ‏36 KB

Maybe you are looking for

  • Can you have two copies of Encore CS6 running on the same computer?

    I'd love to be able to have two copies of Encore on the same computer. While one copy is encoding and burning, I'd love to get another project started and encoding on the same computer and maybe, if possible, even start burning to a separate external

  • Net price rounding issue in PO

    Hi, Please note that I am facing net price rounding issue in PO. For. e.g. In a PO line item  of Qty 25 PC of  base price 6 INR, there is a discount of 3.64 INR. So gross price = 150 INR (25*6) Net value = 150 - 3.64 = 146.36 No net price = 146.36 /

  • DB Migration and ECC 6.0 Upgrade

    I have a number of questions, we have a SAP R/3 4.7x200 landscape that is currently Windows 2003 and SQL2000 both 32 bit, we want to do the following, move to Windows 2003 and SQL2005 64bit, perform a Unicode and ECC6.0 Upgrade. here are the steps I

  • I have a Brother  HL-2240 that I wont allow me to print in my Mac Book Bro.

    The printer is currently installed in my windows Dell Machine. However, my macbook pro shows connection to the printer. Im just not to sure what to do to allow to print from my macbok.

  • Workflow Error out while intiatiating forms(Hcm Forms and Process)

    Hi All, Our workflows are getting error out when forms are initated from Portal. Workflows are getting triggered when it comes to a task(all type of tasks) its getting errored. "An exception with the type CX_SY_REF_IS_INITIAL oc curred, but was neith