Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: Need help with creating method for Array.

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with creating method for Array.

    The whole array is referenced by using the name of the array without the []s
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Meaning your method signature will need adjusting as well to specify the correct data type

  3. #28
    Member
    Join Date
    Dec 2012
    Location
    Detroit Mi
    Posts
    122
    My Mood
    Amazed
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Re: Need help with creating method for Array.

    Okay well I made my method a void, so it would not return anything. So my question if I don't return anything I will store the array in the main method for further use?

    --- Update ---

    I'm trying something right now.

  4. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Basically yes, although you need to edit your methods so you are working on the array you have passed to the method, not creating a new one and working on that as any data you create in a method will be destroyed when the method completes execution...
    So what you want is: create your array in the main method, pass that array to your first method (can be a void method) make the necessary changes to THAT array, any changes to the array will reflect on the original one because it is a non-primitive data type, then back in your main method you pass the same array to the print method which is also void, and make sure that it's printing the correct array...

  5. The Following User Says Thank You to Hammet27 For This Useful Post:

    Rain_Maker (March 24th, 2013)

  6. #30
    Member
    Join Date
    Dec 2012
    Location
    Detroit Mi
    Posts
    122
    My Mood
    Amazed
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Re: Need help with creating method for Array.

    okay I was actually thinking about doing that. I'm going to try that.

  7. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with creating method for Array.

    Using a "global" for passing and returning values from methods is not the way to it.
    Have the method return the array of Strings that it creates.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. help with creating a method and returning a value
    By kungfuthug in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 17th, 2013, 07:22 PM
  2. Creating method to change money?
    By j4ze in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 19th, 2012, 04:21 PM
  3. creating a new method that's not outputting correct result
    By orbin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 23rd, 2012, 12:12 AM
  4. Help Creating a method for my jellyBean gussing game
    By CookiesForRandy in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 20th, 2010, 09:29 AM
  5. Creating a scaleUp main method in a new class
    By Brainz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2010, 08:58 AM