Difference between revisions of "Return Array"
From CompSciWiki
Line 3: | Line 3: | ||
|Problem= Write a method which will take an array of ints as a parameter. | |Problem= Write a method which will take an array of ints as a parameter. | ||
The method should change the contents of the array to 1-5. Print the array to show the contents have been changed and return it. | The method should change the contents of the array to 1-5. Print the array to show the contents have been changed and return it. | ||
− | Example: | + | <BR>Example: |
int[] n = {45,32,78,45,890};<BR> | int[] n = {45,32,78,45,890};<BR> | ||
returnArray(n);<BR> | returnArray(n);<BR> |
Revision as of 12:42, 30 March 2010
Back to the Program-A-Day homepage
ProblemWrite a method which will take an array of ints as a parameter.
The method should change the contents of the array to 1-5. Print the array to show the contents have been changed and return it.
|
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionThe solution... public static int[] returnArray( int[] n ) { for( int i = 0; i < n.length; i++ ) { n[i] = i; System.out.print( n[i] + "," ); } return n; } | ||
CodeSolutionCode goes here. Please DO NOT put your code in <pre> tags! |