Array and number of occurences


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Array and number of occurences

  1. #1
    Join Date
    Dec 2007
    Posts
    1

    Array and number of occurences

    Hi, i'm sorry but i'm new and poor at java.

    I have to create a program that takes sample data such and counts the number of occurrences of each number in each sample data such as
    1 5 3 4 5 5 5 4 3 2 5 5 5 3 or
    2 3 4 5 6 7 8 9 0 2 3 5 6 8 8 8 9 4 5

    and make the output as:
    0 - 0
    1 - 1
    2 - 1
    3 - 3
    4 - 2
    5 - 7
    6 - 0
    7 - 0
    8 - 0
    9 - 0
    or
    0 - 1
    1 - 0
    2 - 2
    3 - 2
    4 - 2
    5 - 3
    6 - 2
    7 - 1
    8 - 4
    9 - 2

    i also have to make the main method in a seperate file of the class, while using a Scanner. Can anyone help me? Even if it's just the beginning of the code?

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The place to start is thinking about and deciding on how your program will work. You have three "functions" to perform: Getting the data (from user or file or random generation or whatever, the basic functionality should not matter); analyzing the data (occurrence count); and displaying the data.

    I am a little confused by the "main method in a separate file of the class" phrase. Are you supposed to be writing 2 classes - one being the black box into which you send your data and out comes the analysis, with all of the interaction with the user being performed in a "driver" class? Anyway... this is where you would use Scanner to create an object which will accept the input stream of your choosing and put the data of the correct type into the container that will store it. Your driver would then dispatch the contents of the container to your occurrence analysis class, which might return a properly formatted string for your driver class to hold and then display to the console when requested.

  3. #3
    Join Date
    Dec 2007
    Posts
    1
    I have the same question as nspils . What do you mean by "main method in a seperate file of the class". In any case, to be object oriented, you can write two different classes. One will be to get the input & sort it as per your requirement and return back the result. One to scan & get the input.

    Go through the entire collection classes and try to pick up the correct collection class which you will be using. Please don't reinvent the wheel.

    Once you are decided with the above points, start writing the code.

    Hope this helps.

Similar Threads

  1. Replies: 26
    Last Post: 12-01-2012, 04:12 AM
  2. Determining the smallest number in an array
    By leospyder in forum Java
    Replies: 2
    Last Post: 04-12-2006, 08:14 AM
  3. Dynamically allocating a 2d array
    By nnp in forum C++
    Replies: 6
    Last Post: 11-01-2005, 09:05 AM
  4. Replies: 2
    Last Post: 04-15-2005, 09:06 PM
  5. Replies: 3
    Last Post: 01-11-2001, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center