PrintArray Function

From CompSciWiki
Revision as of 21:35, 4 April 2012 by EllaP (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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