Results 1 to 10 of 10
  1. #1
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default Need a simple and efficient solution.

    Ok heres what i have:
    Just with a lot more than a, b, and c.



    Java Code:
    public int a;
    public int b;
    public int c;
    
    add(Math.random(3));
    
    public void add(int i) {
    switch (i) {
    
    case 1:
    a += 1;
    break;
    
    case 2:
    b += 1;
    break;
    
    case 3:
    c += 1;
    break;
    
    }
    }

    I was told something like an ArrayList and I looked into it but it was very confusing and there were no examples..
    Thanks for help anyone!

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default huh?

    Sam... a simple and efficient solution to do what ? All you said was a, b, c and arraylist. I think that even you don't know what needs to be done. I don't know you're level of Java knowledge, but I would suggest you understanding arrays first. Here's a link to a tutorial:

    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Yes, you only get specific answers from specific questions. Asking us to do something for you is bad enough. It isn't even possible to help when you tell us to do something but you don't say what.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  4. #4
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    can you not see the code?

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Sam... our purpose is not to aggravate or upset the people who ask questions on the forum. If two people tell you that they don't understand the question or problem, then they really don't understand what you need. You haven't explained it. What do you need your program to do?

    I will tell you what I see:

    • A call to an add() method.
    • An add() method that switchs on the argument that is passed to it and will add a 1 to a variable depending on the passed argument. This method returns nothing.

    I really don't understand where the arraylist fits in this picture.

    Do you want to save the results in an arraylist?

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    yes instead of having
    public int a;
    public int b;
    public int c;

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Sam.. I've sent a private message... lets see if we can figure this out in Spanish.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    Hablo Inglés .. Yo sólo soy nuevo en java ..

  9. #9
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    Creo que necesito para usar un HashMap

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Ta bueno.. but we have to speak English in the forum. Just tell us what is it that you want to do?
    • What data do you want to store?
    • How do you want to store it?
    • How do you want to retreive the stored data?
    • What is the data going to be used for?
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Efficient Perfect Number
    By Lite3864 in forum New To Java
    Replies: 4
    Last Post: 11-23-2008, 02:07 AM
  2. Replies: 0
    Last Post: 08-19-2008, 05:44 PM
  3. How to write efficient maintainable code.
    By Zosden in forum Advanced Java
    Replies: 9
    Last Post: 05-01-2008, 05:48 AM
  4. Simple serverless chat solution
    By goodjonx in forum Networking
    Replies: 3
    Last Post: 01-07-2008, 04:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •