• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The return statement question

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont worry people! I've seen the error of my ways
 
Jean Fore
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic