{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 17-Arrays

Lecture 17-Arrays - CS1110 28 October 2010 Arrays(secs...

Info icon This 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 field 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.
Image of page 1

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

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

{[ snackBarMessage ]}