Foundations of Programming: Arrays

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
1 BUILDING JAVA PROGRAMS CHAPTER 7.1 ARRAY BASICS.
Working With Objects Tonga Institute of Higher Education.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
310201: Fundamental Programming Fundamental Programming Introduction to Arrays.
String and Lists Dr. José M. Reyes Álamo.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
Arrays.
4. Java language basics: Function
Arrays 3/4 By Pius Nyaanga.
© 2016 Pearson Education, Ltd. All rights reserved.
Array, Strings and Vectors
Accumulators in Programming
Error Handling Summary of the next few pages: Error Handling Cursors.
Strings A string is a sequence of characters treated as a group
Arrays in C.
Objects First with Java CITS1001
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Two-Dimensional Arrays
C-Programming, continued
AP Java Unit 3 Strings & Arrays.
Arrays, For loop While loop Do while loop
What is an Array? Why Arrays? Programming Examples.
Peer Instruction 6 Java Arrays.
Java for Beginners University Greenwich Computing At School DASCO
Week 9 – Lesson 1 Arrays – Character Strings
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Arrays November 8, 2017.
ARRAYS 1 GCSE COMPUTER SCIENCE.
CIS 110: Introduction to Computer Programming
Object Oriented Programming in java
Variables Title slide variables.
Java Lesson 36 Mr. Kalmes.
Module 4 Loops.
String and Lists Dr. José M. Reyes Álamo.
Grouped Data Arrays, and Array Lists.
Arrays ICS2O.
Manipulating Pictures, Arrays, and Loops
CPS120: Introduction to Computer Science
Fundamental Programming
Building Java Programs
Java for Beginners University Greenwich Computing At School DASCO
Arrays in Java.
Suggested self-checks: Section 7.11 #1-11
Peer Instruction 4 Control Loops.
Java: Variables, Input and Arrays
Learning Plan 5 Arrays.
Multidimensional Arrays Section 6.4
1D Arrays and Lots of Brackets
Arrays and Pointers CSE 2031 Fall May 2019.
AP Java Unit 3 Strings & Arrays.
CONTENTS     Enter text Enter text Enter text Enter text
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
Arrays and Pointers CSE 2031 Fall July 2019.
Arrays Introduction to Arrays Reading for this Lecture:
1D Arrays and Lots of Brackets
Java Coding 6 David Davenport Computer Eng. Dept.,
Why not just use Arrays? Java ArrayLists.
Week 7 - Monday CS 121.
Introduction to Pointers
Introduction to Computer Science
String Objects & its Methods
Presentation transcript:

Foundations of Programming: Arrays September 28, 2016

Arrays: Arrays are a special type of variable that stores and manipulates large quantities of data. Arrays store data in variable that can hold more then one specific value. Arrays can store multiple values of the same type. Instead of creating 10 different variables to store the multiples of 10, I can instead create one int Array and store multiples of 10 in that one array.

Creation of Arrays: There are many ways to create an Array. Below I will show you one of the ways to create an array. int[] a = new int[10] ; // Here a created an array that can hold 10 unique values a[0] = 10; a[1] = 20; a[2] = 30; // And so on until the last unit of the array a[9] = 100; // The last index(9) you can use for an Array of size 10 is 9. Now you add brackets after the type (int, double, char, etc.). In this example I gave all of my indexes (0-9) in the array a value, but if you don’t do that those indexes will have ZERO values.

More Creation of Arrays in Java:

Creating an array with all predefined values: Arrays can also be created with already defined values. If I wanted to store my entire name in a String array, I can do that as so: String[] myName = {“William”, “Jose”, “Gutierrez”}; The size of the array is 3, and the indexes are 0, 1, and 2. I can do this with all data types. If I wanted to create a double array that stores the first 5 prime numbers then I can do that as so: double[] primes = {1.0, 2.0, 3.0, 5.0, 7.0}; The size of the array is 5 and the indexes are 0, 1, 2, 3, and 4.

For Loops and Arrays: Arrays are used with for loops a lot because by using for loops I can display all the contents of an array fairly easy. You can use special parameter of arrays to get the length of a particular array. Knowing the length of an array, you can display all the contents of an array in a for loop The parameter is called .length If you have an array of size 4, then . length will return 4, but remember the indexes of that array are 0, 1, 2, and 3. If you try to access an index that is not located within an array, your program will crash because you are trying to access something that doesn’t exist. This is why we use .length

Do Now: Arrays and For Loops Write the output of the program below:

Array Examples