Computer Science 15-100 (Sections T & U), Spring 2008
Class Notes: Review Methods, If Statements, and For Loops
Logistics
- Schedule
- Quiz 4 deferred (to Thursday, perhaps)
- Reading:
- No new reading for today
Topic Outline:
Today, we reviewed writing methods using if statements and for loops, as
well as top-down design with method decomposition. Students were presented
with 3 problems. Each was discussed, then students had time to solve the
problems, then a solution was presented to the students. The topics
covered:
- Repeatedly read in a positive integer N and print out all the prime
numbers in the range [2,N].
- Repeatedly read in a positive integer N and print out all the "special"
numbers in the range [2,N], where a number is special if it is both a
perfect square and a perfect cube.
- Repeatedly read in a string and print out whether or not the string is a
palindrome (the same in reverse). This has two cases: in the
easier case, your match should consider capitalization, spacing, and
punctuation (so you just compare the ith character from the left with the
ith character from the right); in the harder (and more interesting) case,
your match should proceed without regard to capitalization, spacing, or
punctuation -- so "Madam, I'm Adam!" is a palindrome.
carpe diem -
carpe diem - carpe diem - carpe diem
- carpe diem - carpe diem -
carpe diem - carpe diem - carpe
diem