Spring 2023 CSE 121 Lesson 5: Coding Concepts and Nested Loops

cse 121 lesson 5 n.w
1 / 10
Embed
Share

Explore the intricacies of coding in the Spring 2023 CSE 121 Lesson 5 with topics covering control structures like for loops, fencepost patterns, and nested loops. Engage with the material through creative projects and quizzes while delving into the fundamentals of Java programming.

  • Spring 2023
  • CSE 121
  • Coding Concepts
  • Nested Loops
  • Java Programming

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSE 121 Lesson 5 Miya Natsuhara Spring 2023 Music: 121 23sp Lecture Vibes TAs: Jasmine Shananda Vidhi Larry Jacqueline Afifah Atharva Julia Anju Lydia Jonus Hugh Mia Archit Grace Kailye Joshua James Justin Aishah Claire Lydia Kai sli.do #cse121

  2. Announcements, Reminders Creative Project 1 is out, due Tues April 18 Resubmission Cycle 0 released yesterday, due Thurs April 20 Feedback for C0 was released yesterday Start tracking your grades in our Minimum Grade Guarantee Calculator Quiz 0: Thursday, April 20 during section Lesson 5 - Spring 2023 2

  3. Last time: for loops! For loops are our first control structure A syntactic structure that controls the execution of other statements. Lesson 5 - Spring 2023 3

  4. Fencepost Pattern Some task where one piece is repeated n times, and another piece is repeated n-1 times and they alternate g-u-m-b-a-l-l Lesson 5 - Spring 2023 4

  5. Fencepost Pattern Some task where one piece is repeated n times, and another piece is repeated n-1 times and they alternate g-u-m-b-a-l-l Lesson 5 - Spring 2023 5

  6. (PCM) Nested for loops for (int outerLoop = 1; outerLoop <= 5; outerLoop++) { System.out.println("outer loop iteration #" + outerLoop); for (int innerLoop = 1; innerLoop <= 3; innerLoop++) { System.out.println(" inner loop iteration #" + innerLoop); } // at this point, innerLoop is OUT OF SCOPE! System.out.println(innerLoop); } Lesson 5 - Spring 2023 6

  7. Poll in with your answer! What output is produced by the following code? A. B. C. Lesson 5 - Spring 2023 7

  8. Poll in with your answer! What code produces the following output? A. C. B. D. Lesson 5 - Spring 2023 8

  9. (PCM) Random A Random object generates pseudo-random numbers. The Random class is found in the java.util package import java.util.*; Method Description nextInt() Returns a random integer nextInt(max) Returns a random integer in the range [0, max), or in other words, 0 to max-1 inclusive nextDouble() Returns a random real number in the range [0.0, 1.0) Lesson 5 - Spring 2023 9

  10. Pseudo-Randomness Computers generate numbers in a predictable way using mathematical formulas. Input may include current time, mouse position, etc. True randomness is hard to achieve we rely on natural processes e.g., atmospheric noise, lava lamps Lesson 5 - Spring 2023 10

Related


More Related Content