Nested Loops & Arrays CSE 120 Spring 2017

Slides:



Advertisements
Similar presentations
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Advertisements

Arrays.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Loops – While, Do, For Repetition Statements Introduction to Arrays
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
CIS 3.5 Lecture 2.2 More programming with "Processing"
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CSE 1301 Lecture 12 Arrays Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Arrays Chapter 7.
Expressions & Control Flow CSE 120 Spring 2017
Unit 5: Canvas Painter.
Chapter 5 – Making Music: An On-Screen Piano (Part 2 – Using Arrays)
Basic Input and Output CSE 120 Spring 2017
EasyCode Foundations Vocabulary Terms.
© 2016 Pearson Education, Ltd. All rights reserved.
Processing Introduction CSE 120 Spring 2017
Memory, Data, & Addressing II CSE 351 Autumn 2017
Recursion I CSE 120 Spring 2017 Instructor: Teaching Assistants:
Developing an App CSE 120 Spring 2017
Functions in Processing CSE 120 Spring 2017
Algorithmic Complexity I CSE 120 Spring 2017
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Mid-Quarter Review CSE 120 Winter 2018
Functions in Processing CSE 120 Winter 2018
Puzzle App II CSE 120 Winter 2018
Basic Input and Output CSE 120 Winter 2018
Variables & Datatypes CSE 120 Winter 2018
Lecture 9 Arrays Richard Gesick.
CSC 142 Computer Science II
Processing and Drawing CSE 120 Winter 2018
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Arrays, For loop While loop Do while loop
Expressions & Control Flow CSE 120 Winter 2018
Binary Numbers CSE 120 Spring 2017
Outline Altering flow of control Boolean expressions
Developing an App II CSE 120 Spring 2017
Variables & Datatypes CSE 120 Spring 2017
Strings, Puzzle App I CSE 120 Winter 2018
Nested Loops, Arrays CSE 120 Winter 2018
Object Oriented Programming in java
More programming with "Processing"
25 Searching and Sorting Many slides modified by Prof. L. Lilien (even many without an explicit message indicating an update). Slides added or modified.
python.reset() Also moving to a more reasonable room (CSE 403)
24 Searching and Sorting.
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Basic Input and Output CSE 120 Winter 2019
Variables & Datatypes CSE 120 Winter 2019
Loops and Arrays in JavaScript
INC 161 , CPE 100 Computer Programming
Arrays in Java.
Arrays CSE 120 Winter 2019 Instructor: Teaching Assistants:
Suggested self-checks: Section 7.11 #1-11
Data Structures & Algorithms
EECE.2160 ECE Application Programming
Loops & Nested Loops CSE 120 Winter 2019
Buttons & Boards CSE 120 Winter 2019
1D Arrays and Lots of Brackets
1D Arrays and Lots of Brackets
Presentation transcript:

Nested Loops & Arrays CSE 120 Spring 2017 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee Yes, There’s Such Thing as a Professional Drone Racing Pilot What do you get when you combine four powerful electric motors and a light carbon-fiber frame? You get instant speed.  Drone Racing League's Racer 3 can get from zero to 80 mph in under a second.  These are the racing drones featured in The Drone Racing League. The races take place in huge physical spaces, like stadiums and abandoned shopping malls. http://www.thedrive.com/aerial/9079/yes-theres-such-thing-as-professional-drone- racing-pilot

Administrivia Assignments: Midterm in class on Wednesday, 4/26 Creativity Planning due Tuesday (4/18) Find a partner, come up with two proposed programs Portfolio Update 1 due Tuesday (4/18) Binary Practice (4/21) Creativity Assignment (4/24) Midterm in class on Wednesday, 4/26 1 sheet of notes (2-sided, letter, handwritten) Fill-in-the-blank(s), short answer questions, maybe simple drawing

Outline Student Work Showcase For-Loop Review Nested Loops Arrays Arrays and Loops

Custom Logo Cadey Kwon

Lego Family Sarah Liu

Outline Student Work Showcase For-Loop Review Nested Loops Arrays Arrays and Loops

For-Loop Review Loops control a sequence of repetitions Do the same thing (or similar things) over and over again Examples: What is changing?

Example: Circle Loop

Example: Line Gradient

Example: Looping with User Interaction? Draw lines from left side of screen to the horizontal position of the mouse

Example: Draw Lines to mouseX

Outline Student Work Showcase For-Loop Review Nested Loops Arrays Arrays and Loops

Nested Loops Generally a for-loop has a single loop variable that changes with each iteration What if you need/want more things to change? Can nest loops – i.e. put a loop inside of another loop

Example: Dot Grid

Example: 2D Gradient

Outline Student Work Showcase For-Loop Review Nested Loops Arrays Arrays and Loops

Arrays “Structures” that store many values of the same datatype Help us group related data Arrays store large amounts of data that you can access using a single variable name Accessing arrays with loops is very convenient

Arrays “Structures” that store many values of the same datatype Element: a single value in the array Index: a number that specifies the location of a particular element of the array Start from 0 Length: total number of elements in the array Example: Index: 1 2 3 4 Value: 12 49 -2 5 17 length of 5 “element 0” “element 4”

Arrays in Processing Declaration: type[] name Creation: new type[num] e.g. int[] is array of integers, color[] is array of colors Creation: new type[num] e.g. int[] intArr = new int[5]; Default value for all elements is “zero-equivalent” (0, 0.0, false, black) Remember that actual indices are from 0 to num-1 Initialization: {elem0, elem1, …, elemN}; e.g. int[] intArr = {12, 49, -2, 5, 17};

Arrays in Processing Use element: name[index] Get length: name.length In expression, uses value of that index of the array In assignment, modifies value of that index of the array Get length: name.length Example: int[] intArr = {12, 49, -2, 5, 17}; println(intArr[0]); // prints 12 to console intArr[2] = intArr.length; // changes -2 to 5 Index: 1 2 3 4 Value: 12 49 -2 5 17

Example: Lots of Plusses

Example: Index of Smallest Number Algorithm: Keep track of the index of the smallest number seen so far Start with index 0 Check each element 1-by-1; if number is smaller, then update the smallest index