11-09 Class Notes CS 107

11-09 Class Notes CS 107 - 11-09 Class Notes CS 107...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 11-09 Class Notes CS 107 Wednesday, November 09, 2011 2:54 PM Announcements: In-class portion of midterm has been graded and emailed to you. See the updated overall grades online. Deadline for program #5 has been extended Anyone find an RCA mp3 player after the Wed 9-9:50 lab? Questions? Last Time: Description of details for program #5 Today: Recursion, continued... Recursion traces //Illustrate simple recursion examples. import java.util.Scanner; // for keyboard input public class Recursion1 { Scanner keyboard = new Scanner( System.in); // Run all examples public void doAllProblems() { System.out.println("f1(8,3) = " + f1(8,3) ); System.out.println("f1(3,8) = " + f1(3,8) ); System.out.println("f2(2,4) = " + f2(2,4) ); System.out.println("f3(256) = " + f3(256) ); System.out.println("f4( 2,5) = " + f4( 2,5) ); } public int f1( int num1, int num2) { if (num1 > num2) return 0; else if (num2 == (num1 + 1)) return 1; else return f1( num1 + 1, num2 -1) + 2; CS 107 Fall 2011 Page 1 return 1; else return f1( num1 + 1, num2 -1) + 2; } public double f2( double x, int n) { if (n == 0) return 0; else return x + f2( x, n-1); } // try this one with input of 256 int f3( int n) { if (n < 0) return f3(-n); else if (n<10) return n; else return f3( n/10); } // Call this with f4( 2,5) double f4( double x, int n) { if (n == 0) return 1.0; else if (n > 0) return f4( x, n - 1) * x; else { System.out.println("Error !"); return 0.0; } } }//end Class Recursion1 The "maze" problem: See other document under today's notes CS 107 Fall 2011 Page 2 ...
View Full Document

This note was uploaded on 02/10/2012 for the course COP 2273 taught by Professor Lin during the Fall '11 term at University of Central Florida.

Page1 / 2

11-09 Class Notes CS 107 - 11-09 Class Notes CS 107...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online