What we will do today
description
Transcript of What we will do today
![Page 1: What we will do today](https://reader036.fdocuments.us/reader036/viewer/2022082422/56813f31550346895da9d4b0/html5/thumbnails/1.jpg)
What we will do today1. You’ll try to write a recursive function to solve a simple
problem2. We’ll return to the count number of “a”s example from
the previous day, and I’ll explore it a bit more3. I’ll discuss an alternative recursive string function4. I’ll discuss the “natural” recursive structure of files and
directories, and go through a example with that5. You will also write a recursive function with files and
directories6. If we have time: even more practice with recursive
functions
![Page 2: What we will do today](https://reader036.fdocuments.us/reader036/viewer/2022082422/56813f31550346895da9d4b0/html5/thumbnails/2.jpg)
First Recursion Problem
• Go to http://codingbat.com/java/Recursion-1• Solve count7• If you finish, solve bunnyEars2• If you finish, do fibonacci (this one is so old
that I solved in my very first CS class…and it was pretty dang old then)
• If you finish, do a tiny green dance in your chair and then move on to some more
![Page 3: What we will do today](https://reader036.fdocuments.us/reader036/viewer/2022082422/56813f31550346895da9d4b0/html5/thumbnails/3.jpg)
public int countAs(String input) { if(input.isEmpty()) return 0; String restOfString = input.substring(1); int restOfStringCount = countAs(restOfString); if(input.charAt(0) == 'a') { return restOfStringCount + 1; } else { return restOfStringCount; } }
![Page 4: What we will do today](https://reader036.fdocuments.us/reader036/viewer/2022082422/56813f31550346895da9d4b0/html5/thumbnails/4.jpg)
A genuinely good example of recursion
How would you find the largest file within a directory (oh, and this directory can contain other directories)