Results 1 to 14 of 14
  1. #1
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Question problem in a method which return array format

    Hi, I want to create a method which return an array of integers. I want to ask, How can I get the data of that array which the explained method return?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: problem in a method which return array format

    What? What's your question? What have you tried? Where are you stuck?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Default Re: problem in a method which return array format

    as I said earlier, suppose a method like below retun an array as it's output! How can I get the data of the method in another method, How can I get the data of array?
    Public int[] method(){
    Int[] array = new int[2]
    Array[0]=0;
    Array[1]=1;
    Return array;
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    Does your code work (after you correct the case problems)?
    When you call a method that returns a value, you need to have a variable of the correct type to assign that value to. If the method returns an integer array, then the variable to get that returned value must be an integer array.

    For further discussion, Make a complete program from your example, adding an other method that calls method.

  5. #5
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Default Re: problem in a method which return array format

    my problem is, How can I get the data of array and set each datum of the array in an integer?
    for example I want to call the Method method which return an array and set the first datum in on Integer value and the other in second Integer value? How can I do this?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    I want to call the Method method which return an array and set the first datum in on Integer value and the other in second Integer value
    You can either set the values of the elements of the array in method
    or you can set them in the code that receives the returned array after the call to method.
    Your choice.

    Your post#3 set values of the elements in the array in method.

  7. #7
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Default Re: problem in a method which return array format

    my problem is How to set the data in the values? could you show me a sample code plz?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    Array[0]=0;
    This sets the value of the first element in the array to 0.

  9. #9
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Default Re: problem in a method which return array format

    I have written this earlier, I mean with using the method Method which return an array How can I set the values in an Integer value?

    for example:

    int[] x= new int[2];
    x[0]=method();
    x[1]=method();
    but it's not true! I mean how can I fill the X array which method returned values?

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    Your post#9 did NOT define what method returns. You have coded it like it returns an int value:
    x[0]=method();
    or this also would be a valid statement:
    int anInt = method();

    In post #3 you defined it as returning an int array:
    Public int[] method(){

    I tried to explain how in post#4:
    When you call a method that returns a value, you need to have a variable of the correct type to assign that value to. If the method returns an integer array, then the variable to get that returned value must be an integer array.

    What does method return? an int or an int[]
    When you define what it returns then the variable that receives what it returns must be the same type.

  11. #11
    elenora is offline Member
    Join Date
    Apr 2011
    Posts
    30
    Rep Power
    0

    Exclamation Re: problem in a method which return array format

    int[];
    the method return an array! I think you don't understand me, I'm sayin I want to get the data of the array which method retuns, How can I get it? I wrote the sample code to understand you about my prob! I want the data of the array in another method!

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    I want the data of the array in another method!
    Can you write a small simple program with all the methods and arrrays you are talking about so there is something concrete to discuss. Please do NOT name your array array or your method method. That makes for some ambiguity when using those terms if there are program parts with the same name.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: problem in a method which return array format

    Ok, glad you figured it out.

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: problem in a method which return array format

    That's a different poster...though it can be hard to tell.
    I suspect (by the lack of content in that post) that it's someone warming up to post spam.

Similar Threads

  1. Problem with method & return
    By bigsonny in forum New To Java
    Replies: 32
    Last Post: 03-23-2011, 03:46 AM
  2. Problem with my return method
    By braddy in forum New To Java
    Replies: 4
    Last Post: 10-19-2010, 06:34 AM
  3. Replies: 18
    Last Post: 12-02-2009, 12:01 PM
  4. Method return type problem
    By McChill in forum New To Java
    Replies: 7
    Last Post: 05-05-2009, 09:21 PM
  5. Replies: 2
    Last Post: 04-16-2008, 12:35 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
  •