Warning This class is being recorded.
Getting started (this will be our normal start-of-class sequence)
For the future: I’m happy to reserve a (somewhat random) seat at the front of the classroom for those who need a front seat as an adjustment or accommodation. Just let me know.
Approximate overview
Academic
Cultural
Peer
Wellness
Do we really have SoLAs?
No.
Are you going to post readings from the book?
Um … yeah, that’s in the plan. We’ll be using CLRS starting around week six.
We’ll mostly be using my readings. CLRS provides more formality.
There are old editions of CLRS in the CS learning center and a legal free edition online through the library.
main
, create a PrintWriter
named pen
and
use fizzbuzz(pen, 100)
.PrintWriter
objects rather than System.out
because it makes it easier to change the behavior of your program.
fizzbuzz(new PrintWriter(System.out, true), 100)
fizzbuzz(new PrintWriter(new File("killbuzz.txt"), 1000))
A standard approach: Four cases (multiple of 15, multiple of 5, multiple of 3, anything else)
if (i % 15 == 0) {
pen.println("fizzbuzz");
}
else if (i % 5 == 0) {
pen.println("buzz");
}
else if (i % 3 == 0) {
pen.println("fizz");
}
else {
pen.println(i);
}
An alternate approach: Always print fizz when it’s a multiple of 3, always print buzz when it’s a multiple of 5, add appropriate extra stuff.
boolean printed = false;
if (i % 3 == 0) {
pen.print("fizz");
printed = true;
}
if (i % 5 == 0) {
pen.print("buzz");
printed = true;
}
if (!printed) {
pen.print(i);
}
pen.println();