ARRAY AND LOOPS REVIEW Mr. Crone. What will the code below print? int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]);

Slides:



Advertisements
Similar presentations
1 More on Arrays and Loops Reading for this Lecture: –Section 5.4, , Break and Continue in Loops Arrays and For-each Loops Arrays and Loops.
Advertisements

Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Chapter 10 Introduction to Arrays
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Lecture 05 - Arrays. Introduction useful and powerful aggregate data structure Arrays allow us to store arbitrary sized sequences of primitive values.
Arrays Chapter 6 Chapter 6.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
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.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Arrays Declare the Array of 100 elements 1.Integers: int[] integers = new int[100]; 2.Strings: String[] strings = new String[100]; 3.Doubles: double[]
Chapter Eight: Arrays 1.Terms and what they mean 2.Types of arrays -One Dimensional arrays -Two Dimensional arrays -ragged arrays -Parallel arrays 3. Methods.
Chapter 9: Arrays and Strings
Chapter 9 Introduction to Arrays
Java Unit 9: Arrays Declaring and Processing Arrays.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
7. Arrays. Topics Declaring and Using Arrays Some Array Algorithms Arrays of Objects Variable Length Parameter Lists Two-Dimensional Arrays The ArrayList.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Java Programming: From Problem Analysis to Program Design, 4e
AP Comp Sci A Chapter 12 - Arrays. Ch 12 Goals: Goals: Declare and create arrays Declare and create arrays Access elements in arrays Access elements in.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays.
Chapter 9: Arrays J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
2D-Arrays Quratulain. Learning Objectives Two-dimensional arrays Declaration Initialization Applications.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
8-1 Chapter 8: Arrays Arrays are objects that help us organize large amounts of information Today we will focuses on: –array declaration and use –bounds.
Arrays - The Movie A Farelly Brothers Presentation. No. Not Really.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Enhanced For Loops (For Each Loops) Less Code and Less Overhead for Writing For Loops.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 7.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
IT259 Foundation of Programming Using Java Unit 9 Seminar : (Chapter 8 ) Instructor : Vladimir Gubanov, PhD
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Chapter 5: ARRAYS ARRAYS. Why Do We Need Arrays? Java Programming: From Problem Analysis to Program Design, 4e 2  We want to write a Java program that.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
1 Chapter 9 Arrays Java Programming from Thomson Course Tech, adopted by kcluk.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
ARRAYS Multidimensional realities Image courtesy of
Arrays. Arrays are objects that help us organize large amounts of information.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Lesson 9 Arrays. Miscellaneous About Arrays An array is an object. Because of this, the array name is a reference variable Therefore, in order to start.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Two Dimensional Array Mr. Jacobs.
AP Search and Sort Review
SELECTION STATEMENTS (1)
Arrays, For loop While loop Do while loop
Topics Covered: Arrays, 1-D & 2-D Passing & Returning Arrays
Presentation transcript:

ARRAY AND LOOPS REVIEW Mr. Crone

What will the code below print? int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]);

int[] arry = {2, 5, 2, 1, 3}; for(int i = 0; i < 5; i ++) System.out.print(arry[i]); // prints: 25213

Does the code below alter Array arry? int[] arry = {3,1, 3, 4}; for(int i = 0; i < 4; i ++) arry[i] / 2;

Does the code below alter Array arry? int[] arry = {3,1, 3, 4}; for(int i = 0; i < 4; i ++) arry[i] / 2; // Does nothing! // Should be: arry[i] = arry[i] / 2

//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}}; System.out.println(arry.length);

//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}}; System.out.println(arry.length); // 2

//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}, {"Roy", "Nascar", "Basketball", "River"}}; System.out.println(arry[2].length);

//What will the code below print? String[][] arry = {{"hi", "mine", "boo", "Harry"}, {"zoo", "food", "dog", "Water"}, {"Roy", "Nascar", "Basketball", "River"}}; System.out.println(arry[2].length); // 4

What does the code below do/print? int[] arry = {2, 5, 2, 1, 3}; int min = arry[0]; for(int i = 1; i < 5; i ++){ if(arry[i] < min) min = arry[i]; } System.out.println(min);

What does the code below do/print? int[] arry = {2, 5, 2, 1, 3}; int min = arry[0]; // Initialized min to first element for(int i = 1; i < 5; i ++){ if(arry[i] < min) // Checks each element’s size min = arry[i]; //Keeps track of smallest num. } System.out.println(min);

What are parallel arrays?

// Parallel arrays are multiple arrays in which corresponding elements are related.

Instantiate a one-dimensional array with an initializer list.

int[] arry = {1, 2, 3, 4, 5};

What happens when a program attempts to access an item at an index that is less than zero or greater than or equal to the array’s length? Name the type of error.

//ArrayIndexOutofBoundsException.

What will the code below print? int[] arry = {34, 23, 67, 89, 12}; System.out.print( a[a.length - 1] );

What will the code below print? int[] arry = {34, 23, 67, 89, 12}; System.out.print( a[a.length - 1] ); // a[4] // 12

What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[1] + 5);

What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[1] + 5); // 10

What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[arry[0]]);

What does the code below print: int[] arry = {2, 5, 1, 6}; System.out.print(arry[arry[0]]); // 1

What does the code below print: int[] arry = {2, 5, 3, 6}; System.out.print(arry[arry[2]] * 2);

What does the code below print: int[] arry = {2, 5, 3, 6}; System.out.print(arry[arry[2]] * 2); // 12

True or False The for-loop below will access every element in the array arry. int[] arry = {2, 5, 3, 2, 1}; for(int i = 1; i <= 5; i ++){ arry[i] = arry[i] + 1; }

True or False The for-loop below will access every element in the array arry. int[] arry = {2, 5, 3, 2, 1}; for(int i = 1; i <= 5; i ++){ arry[i] = arry[i] + 1; } // False

Declare and instantiate a two dimensional Integer array called table that has 5 rows and 6 elements in each row.

Declare and instantiate a two dimensional int array called table that has 5 rows and 6 elements in each row. // int[][] table = new int[5][6];

What is the difference between the physical size and logical size of an array?

//Physical is the actual size of the array. Logical is how many elements are currently being used.

What is a ragged array?

// A two dimensional array that has different number of elements in each row.

Final Question! What will the code below print? String[][] arry = {{“hi”, “Mine”, “boo”}, {“zoo”, “food”, “dog”}}; int sum = 0; for(int i = 1; i < 3; i ++) sum += arry[0][i].length(); System.out.print(sum + arry.length);

Final Question! What will the code below print? String[][] arry = {{“hi”, “Mine”, “boo”}, {“zoo”, “food”, “dog”}}; int sum = 0; for(int i = 1; i < 3; i ++) sum += arry[0][i].length(); // sum = 7 System.out.print(sum + arry.length); // = 9!