Difference between revisions of "Passing Arrays"

From CompSciWiki
Jump to: navigation, search
Line 6: Line 6:
 
[[Image:Wiki_array01.jpg|center]]<BR>
 
[[Image:Wiki_array01.jpg|center]]<BR>
  
|Solution=
+
|Solution=First step is to create skeleton structure of the program. The methods will looks something like this:
 +
<pre>
 +
public static int[] createArray(int n){
 +
}
 +
public static int addArray(int[] array){
 +
}
 +
public static void setZeroes(int[] array){
 +
}
 +
</pre>
 +
In the main program there is no need
  
 
|SolutionCode=
 
|SolutionCode=

Revision as of 10:55, 8 April 2010

Back to the Program-A-Day homepage

Problem

Write a program with 3 separate methods. One method will create an integer array, it will take an integer parameter as the size of the array to create and return the newly created array. Second method will take an integer array and add the contents of it and return the total. Third method will take an array set all the value in the array to 0 and will not return the array back.

 

Introducing Arrays

Wiki array01.jpg

Solution

First step is to create skeleton structure of the program. The methods will looks something like this:

public static int[] createArray(int n){
}
public static int addArray(int[] array){
}
public static void setZeroes(int[] array){
}

In the main program there is no need

Code

Solution Code

Back to the Program-A-Day homepage