Difference between revisions of "PrintArray Function"

From CompSciWiki
Jump to: navigation, search
 
(typo ("complete"), incomplete sentences (first sentence of intro), added a semicolon ("Write the main function as follows:"))
 
Line 1: Line 1:
 
{{1010PrAD|ProblemName=printArray Method
 
{{1010PrAD|ProblemName=printArray Method
  
|Problem= Write a function that takes an array as its parameter and then print the elements in the array
+
|Problem= Write a function that takes an array as its parameter and then print the elements in the array.
 
|SideSectionTitle=Arrays and Functions
 
|SideSectionTitle=Arrays and Functions
 
|SideSection=
 
|SideSection=
 
|Solution=
 
|Solution=
Write the main function
+
Write the main function as follows:
  
 
{{CodeBlock
 
{{CodeBlock
Line 26: Line 26:
 
}}
 
}}
  
Now your task is to compelete the printArray function.
+
Now your task is to complete the printArray function.
  
 
|SolutionCode=
 
|SolutionCode=

Latest revision as of 21:35, 4 April 2012

Back to the Program-A-Day homepage

Problem

Write a function that takes an array as its parameter and then print the elements in the array.

 

Arrays and Functions

Solution

Write the main function as follows:

 def main():
  #class list for comp 1010
  String [] comp1010 = { "Adam", "Bob", "Carl", "David", "Edward"};	
  #class list for comp 1020
  String [] comp1020 = { "Amy", "Beth", "Cindy", "Dawn", "Ellen"};
  #class list for comp 1260
  String [] comp1260 = { "Mike", "Mary", "Matthew", "Megan", "Moe"};

  print 'comp1010:\n'
  printArray(comp1010)
  print 'comp1020:\n'
  printArray(comp1020)
  print 'comp1260:\n'
  printArray(comp1260)
main() 

Now your task is to complete the printArray function.

Code

Solution Code

Back to the Program-A-Day homepage