Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2011
    Posts
    7
    Rep Power
    0

    Default Array for counting from 1 to 100

    Here's the assignment:
    Write methods for the following:
    a)Find and return the total sum of numbers stored in an ArrayList.
    b)find and return the maximum number from the ArrayList.
    c)Find and return the minimum number from the ArrayList.
    d)Find and return the mean of all the numbers from the ArrayList.
    Write a tester class that creates an ArrayList of numbers. Add numbers from 1 to 100 to the ArrayList. Call all the utility methods from your utility class on the ArrayList that you have created. Print the results obtained.

    I don't know how to get the ArrayList to count.

    here's my thoughts, but I don't know how to get it to work, it's messing up.

    ArrayList<Integer> numbers = new ArrayList<Integer>();
    {
    for(int i=0; i<numbers.size(); i++)
    {
    numbers [i]=i+1;
    }

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Array for counting from 1 to 100

    try get() method of ArrayList.
    SEE: ArrayList (Java Platform SE 6)
    The Really Big Index

  3. #3
    Join Date
    Sep 2011
    Posts
    7
    Rep Power
    0

    Default Re: Array for counting from 1 to 100

    Like how would I do this in code though, I don't understand Arrays at all

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Array for counting from 1 to 100

    Quote Originally Posted by Magic8ballfollower View Post
    Like how would I do this in code though, I don't understand Arrays at all
    We're not going to do your work for you. You've gotten a good suggestion and a link to the tutorials. I suggest you read and study the tutorial so you do understand ArrayLists, and then come back with your new code if you get stuck.

  5. #5
    Join Date
    Sep 2011
    Posts
    7
    Rep Power
    0

    Default Re: Array for counting from 1 to 100

    the "help" he gave is a link to a crappy site that isn't helping at all, and his reply didn't answer or corrrect anything I've already posted

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Array for counting from 1 to 100

    Quote Originally Posted by Magic8ballfollower View Post
    the "help" he gave is a link to a crappy site that isn't helping at all, and his reply didn't answer or corrrect anything I've already posted
    That "crappy" site is where many of us, myself included, learned how to code in Java. The more you use the site, the less crappy and more useful it will become and the better coder you will be. Also, you really didn't ask any direct question in your first post. It isn't really our job to correct your code, but to try guide you so that you can learn about the concepts needed to correct it yourself. Otherwise we would be cheating you out of learning something well.
    Last edited by Fubarable; 09-22-2011 at 06:09 AM.

Similar Threads

  1. Need help with counting strings in an array.
    By dalonehunter in forum New To Java
    Replies: 1
    Last Post: 10-02-2009, 09:47 AM
  2. Array help counting # of grades
    By speaknspell in forum New To Java
    Replies: 4
    Last Post: 04-16-2009, 11:09 PM
  3. Replies: 3
    Last Post: 12-14-2008, 02:52 PM
  4. Counting Duplicate Variables in an Array
    By Npcomplete in forum New To Java
    Replies: 2
    Last Post: 10-24-2008, 08:33 PM
  5. Counting the number of columns in a 2D array,
    By KalEl in forum New To Java
    Replies: 9
    Last Post: 10-21-2008, 06:27 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
  •