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?:)-:
Printable View
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?:)-:
What? What's your question? What have you tried? Where are you stuck?
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;
}
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.
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?
You can either set the values of the elements of the array in methodQuote:
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
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.
my problem is How to set the data in the values? could you show me a sample code plz?
Array[0]=0;
This sets the value of the first element in the array to 0.
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?
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.
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!
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.Quote:
I want the data of the array in another method!
Ok, glad you figured it out.
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.