Lecture 17-Arrays - 10/28/10 CS1110 28 October 2010 Arrays...

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

View Full Document Right Arrow Icon
10/28/10 1 1 On (computational) simplicity We are trying to teach not just Java, but how to think about problem solving . Computer science has its feld called computational complexity; mine is called computational simplicity. – ProF. Gries Most oF us don’t write perFect essays in one pass, and coding is the same: writing requires revising; programming requires revising . IF you are writing too much code —it gets longer and longer, with no end in sight: stop and look For a better way . IF your code is getting convoluted and you have trouble understanding it: stop and look For a better way . Learn to keep things simple, to solve problems in simple ways. This sometimes requires a diFFerent way oF thinking. A key point is to break a problem up into several pieces and do each piece in isolation, without thinking about the rest oF them. Our methodology For developing a loop does just that. CS1110 28 October 2010 Arrays (secs 8.1-8.3) 2 Zune error http://tinyurl.com/9b4hmy /* day contains the number oF days since ORIGINYEAR ( 1 Jan 1980) */ /* Set year to current year and day to current day oF current year */ year = ORIGINYEAR; /* = 1980 */ while (day > 365) { iF (IsLeapYear(year)) { iF (day > 366) { day= day – 366; year= year + 1; } } else { day= day – 365; year= year + 1; } } Zune clock code keeps time in seconds since beginning oF 1980. It calculates current day and year From it. Example year day 1980 738 1981 372 1982 7 On 31 Dec 2008, the Zune stopped working. Anger! On 1 Jan 2009 it worked. Does each iteration make progress toward termination? Not iF day == 366!! 3 Array : object that stores lists oF things. Holds a
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/27/2010 for the course CS 9339 at Cornell University (Engineering School).

Page1 / 2

Lecture 17-Arrays - 10/28/10 CS1110 28 October 2010 Arrays...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online