aspose file tools*
The moose likes Beginning Java and the fly likes The return statement question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The return statement question" Watch "The return statement question" New topic
Author

The return statement question

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
I have a program with the following structure:


I want to pass an array from the InstantiateArray method to the EvaluateArray method and I want to return that score back to the InstantiateArray method. I know the key word is return and I know how to return it to the InstantiateArray method, BUT, i dont know how to invoke the EvaluateArray method in the first place.

How do i do this?

I have tried

Program1 arr = new Program1();

in the InstantiateArray() method but this does not produce the correct score that I know that EvaluateArray method has actually calcualted. Instead it returns 0

Cheers
[ March 02, 2006: Message edited by: Sam Bluesman ]

Moosey knows best
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
Dont worry people! I've seen the error of my ways
Jean Fore
Ranch Hand

Joined: Feb 23, 2006
Posts: 33
Hi,
I tried this program by making some changes in that :

public class Program1
{

public int[] InstantiateArray(int[] array) // Note the return type
{
for (int i=0; i <array.length; i++)
{
array[i] = i;
}
EvaluateArray(array); // Calling the EvaluateArray method.
return array; // returning the changed array
}
public int[] EvaluateArray(int[] array) // Note the return type
{
for (int i=0; i <array.length; i++)
{
array[i] = i*2;
}
return array; // returning the changed array
}

public static void main(String[] args)
{
int[] array = new int[10];
Program1 pr1 = new Program1();
pr1.InstantiateArray(array); // call to the first method
System.out.println("length "+array.length);
for (int i=0; i <array.length; i++)
{
System.out.println(array[i]);
}

}
}


Hope this helps!!
Thanks
JEAN
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The return statement question
 
Similar Threads
Nested/Inner classes Example program
passing array in to method...doubt
classes, help
How can I call my obj in another program?
How to encode image in parts?