Difference between revisions of "Print Array"

From CompSciWiki
Jump to: navigation, search
Line 23: Line 23:
  
 
|Code=
 
|Code=
 
+
<pre>
 
public static void printArray( int[] n )
 
public static void printArray( int[] n )
 
{
 
{
Line 31: Line 31:
 
   }
 
   }
 
}
 
}
 +
</pre>
  
  
 
}}
 
}}

Revision as of 11:37, 6 April 2010

Back to the Program-A-Day homepage

Problem

Write a method which will take an array of ints as a parameter. The method should print the elements of the array, separated by a comma.
Example: int[] n = {45,32,78,45,890,45,32};
printArray(n);
Output:45,32,78,890,45,32

 

SideSectionTitle

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

To solve this problem you need to use a for loop. Loop from 0 through all elements of the input array. At each iteration, print out the current array element and a comma.

Code

SolutionCode goes here. Please DO NOT put your code in <pre> tags!

Back to the Program-A-Day homepage