This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 15-121 FALL 2009 [CORTINA/REID-MILLER]LAB 7In this lab, you will implement several recursive methods. EXERCISESDownload the project Lab7.zip. This project has three classes, one for each exercise below. Complete the required methods below. 1. Write a recursive method factorialthat has one parameter, a positive integer n, and returns n-factorial. n! = 1*2*3*...*n In a comment write what is the largest value of n, for which factorialgives correct values? (HINT: the smallest n that it incorrect is not when it returns a negative number.) How do you know it is incorrect? Can you write a tester to find this n? Change your method to use longinstead of int. Now what is the largest value of n for which factorialgives correct values? 2. Write a recursive method countthat has two parameters, a string and a character, and it returns the number of times the character appears in the string. You may only use the following String methods as necessary: charAt, substring, equals, length....
View Full Document
This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.
- Spring '09