1 / 12

Announcements & Review

Announcements Examples posted after lecture on schedule Discussion Section exercises on line before 9am Tuesdays Lab 2 Due Thursday 10pm. Last Time: Compilation Scaffolding print(): displays a value println(): displays a value and moves cursor to the next line.

edmund
Download Presentation

Announcements & Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Announcements Examples posted after lecture on schedule Discussion Section exercises on linebefore 9am Tuesdays Lab 2 Due Thursday 10pm Last Time: Compilation Scaffolding print(): displays a value println(): displays a value and moves cursor to the next line Announcements & Review Lecture 4: For Loops

  2. Today More on Beauty Analogy: Formatting Paragraphs Sequencing Analogy: a well constructed essay Note on punctuation: end your statements Repetition (i for iteration) for (int i = 0; i < 10; i++) { // your code here } Lecture 4: For Loops

  3. Beauty /* Kathryn S McKinley * September 2005 * file: Song.java - a few lines from a good song * Song: All These Things That I’ve Done * Band: The Killers, Album: Hot Fuss */ public class Song { public static void main (String [] args) { System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”); } } Lecture 4: For Loops

  4. I’m Ugly /* Kathryn S McKinley * September 2005 * file: Song.java - a few lines from a good song * Song: All These Things That I’ve Done * Band: The Killers, Album: Hot Fuss */ public class Song { public static void main (String [] args) { System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”); } } Lecture 4: For Loops

  5. Paragraphs // song lines System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”); Lecture 4: For Loops

  6. Paragraphs // verse System.out.println(“You are going to bring yourself down”); //chorus System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); //verse System.out.println(“Yah yah, you got to help me out.”); Lecture 4: For Loops

  7. Can we do better? // verse System.out.println(“You are going to bring yourself down.”); //chorus System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); //verse System.out.println(“Yah yah, you got to help me out.”); Lecture 4: For Loops

  8. Yes! // verse System.out.println(“You are going to bring yourself down.”); //chorus for (int i =0; i < 10; i++) { System.out.println(“I’ve got soul, but I’m not a soldier. ”); } //verse System.out.println(“Yah yah, you got to help me out.”); Lecture 4: For Loops

  9. For: Definite Loop Three parts for (i = 0; i < 99; i++) { // loop body } • Initialization • Test • Increment Lecture 4: For Loops

  10. For: Definite Loop Three parts for (int i = 0; i < 99; i++) { // loop body in here } • Initialization - int i = 0; • one time only • Test - if i < 99 then execute body • every time • Increment - i++ add 1 to the value of I • every time Lecture 4: For Loops

  11. BlueJ Examples Lecture 4: For Loops

  12. Questions? Lecture 4: For Loops

More Related