Chapter 10 Arrays.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Copyright 2008 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
Reindeer. Rangifer tarandus Also known as the caribou Females weight between 130 and 370 lbs and measures 64–81 inches long. Males weight 220–700 lb and.
Java: How to Program Arrays and ArrayLists Summary Yingcai Xiao.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Types in Java 8 Primitive Types –byte, short, int, long –float, double –boolean –Char Also some Object types: e.g. “String” But only single items. What.
Rudolph the Red Nosed Reindeer. You know Dasher and Dancer and Prancer and Vixen.
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
Introduction to Computing Concepts Note Set 21. Arrays Declaring Initializing Accessing Using with Loops Sending to methods.
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
Rudolph, The Red Nosed Reindeer You know Dasher and Dancer and Prancer and Vixen, Comet and Cupid and Donner and Blitzen. But do you recall the.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
Chapter VII: Arrays.
Arrays Chapter 7.
Single Dimensional Arrays
Arrays in JAVA Visit for more Learning Resources.
Arrays 3/4 By Pius Nyaanga.
Command Line Arguments
Blitzen’s Boogie Teresa and Paul Jennings Music K-8, Vol. 12. Num.2 © 2001 Plank Road Publishing, Inc. All Rights Reserved- used by permission PowerPoint.
Parameter Lists & Command Line Arguments
Get Along, Little Reindeer
C++ Arrays.
CS 1430: Programming in C++.
BIT115: Introduction to Programming
Chapter 10 Arrays.
Arrays An Array is an ordered collection of variables
Chapter 6 Arrays.
Lecture 3 Functions Simple functions
Pass by Reference, const, readonly, struct
Arrays Skill Area 315 Part A
PowerPoint by Susan Will
An Introduction to Java – Part I, language basics
Chapter 8 Multi-Dimensional Arrays
Building Java Programs
Chapter 8 Slides from GaddisText
CS-161 Computer Programming Lecture 14: Arrays I
AP Java Warm-up Boolean Array.
Reindeer Names.
Please make sure that your child reads to you nightly.
CS2011 Introduction to Programming I Arrays (II)
python.reset() Also moving to a more reasonable room (CSE 403)
CS2011 Introduction to Programming I Arrays (I)
Arrays Chapter 7.
class PrintOnetoTen { public static void main(String args[]) {
2D Arrays Just another data structure Typically use a nested loop
1D Arrays and Lots of Brackets
1D Arrays and Lots of Brackets
CS149D Elements of Computer Science
CS150 Introduction to Computer Science 1
Chapter 9: Pointers and String
Chapter 9: Pointers and String
Building Java Programs
C++ Array 1.
Arrays and Pointers CSE 2031 Fall May 2019.
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
Ps Module 7 – Part II 2D Arrays and LISTS 5/26/2019 CSE 1321 Module 7.
Arrays and Pointers CSE 2031 Fall July 2019.
1D Arrays and Lots of Brackets
MIS 222 – Lecture 12 10/9/2003.
Week 7 - Monday CS 121.
Presentation transcript:

Chapter 10 Arrays

Objectives Declare and use arrays in programs. Access array elements within an array. Calculate the sum, largest number, smallest number, and average of a group of numbers by using an array. Setup a program to store the arguments from command line into an array.

Declaring an Array Array - group of contiguous memory locations that all have the same name and the same type.  Declaring an array: int [ ] temp;    // an integer array called temps boolean[ ] hostilePeople;   // an array of hostilePeople String difficultWord [ ];   //  an array of difficultWords double examScore[ ];   // an array of examScores

Creating Array Objects int [ ] temp =  new int [ 250 ] ; String [ ]  reindeerName  = { "Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen"  } ;

Length of Array String n [ ] = { "Mary", "John", "Susan", "Robert" }; int x = n.length; // where n is the name of the array n[ 0 ] = "Mary"; n[ 1 ] = "John"; n[ 2 ] = "Susan"; n[ 3 ] = "Robert"; The length of the array called n is 4. n[2] is "Susan" instead of "John" as you might expect.

Example Array Program public static void main (String args[ ] ){ int number =5; int myArray [ ] = new int[10]; // declares integer array of 10 elements for (int i = 0; i <10; i ++) { myArray[i] = number; // puts 5, 10, 15 into elements of myArray System.out.println("The " + i + " element of the array is " + myArray [ i ] ); number += 5; } The 0 element of the array is 5 The 1 element of the array is 10 The 2 element of the array is 15 The 3 element of the array is 20 The 4 element of the array is 25 The 5 element of the array is 30 The 6 element of the array is 35 The 7 element of the array is 40 The 8 element of the array is 45 The 9 element of the array is 50

Another Way of Writing the Previous Program public static void main (String args[ ] ) { int myArray [ ] = new int[10]; // declares integer array of 10 elements for (int i = 0, number=5; i<10; i ++, number+=5) { myArray[i] = number; // puts 5, 10, 15 into elements of myArray System.out.println("The " + i + " element of the array is " + myArray[i] ); } }

Summing Numbers sum = sum + a; sum= sum + b; sum = sum + c; sum = sum + d; sum = sum + e; OR sum = sum + a + b + c + d + e; OR If the values were in an int array called x, we could do the same thing as follows: for ( i = 0; i < 5 ; i++) { sum = sum + x [ i ]; }

Drawing Polygons