CIS 110 Spring 2013 - Introduction to Computer Programming

upenn.edu | directories | van pelt library
seas.upenn.edu | CETS | engineering library
computer graphics & game dev (SIGGRAPH @ Penn) | dining philosophers (DP) | science & tech wing (STWING) | women in cs (WICS)
CETS Answers

Recitation 2 Exercise

Goals

The goal of recitation exercises is to help you prepare for the topics we will cover in recitation and come ready with questions. You should plan on spending about 30 minutes on recitation exercises before your recitation or the day before.

Exercises

  • Write a program called ForLoopFunctionPractice that creates an array and stores numbers 1 - 10 using a for loop. Using a separate for loop, print the contents of the array with a comma and space in between. For example,

    % java ForLoopFunctionPractice
    
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    
    
  • In the same program, write a function power that takes two ints as arguments representing a number and exponent, and returns an int that is number ^ exponent. For example, power(3, 2) should return 9. Do NOT use Math.pow(). Note: Functions will be covered in Wednesday's lecture, so this exercise may be difficult right now - that is ok.