• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The return statement question

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dont worry people! I've seen the error of my ways
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic