Java Array ISYS 350.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Arrays I Savitch Chapter 6.1: Introduction to Arrays.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
Wednesday, 11/6/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/6/02  QUESTIONS?? – HW # 4 due Monday  Today:  Return HW #3  Arrays (Chap. 10)  Reading:
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Java Arrays [Lists] in 10 Minutes. Declaring an array (and its types) int[] myIntArray; double[] myDoubleArray; String[] myStrings; //What’s the pattern?
Pemrograman Dasar Arrays PTIIK - UB. Arrays  An array is a container object that holds a fixed number of values of a single type.  The length of an.
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.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
Enhanced For Loops (For Each Loops) Less Code and Less Overhead for Writing For Loops.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
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.
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
Arrays.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
ARRAYS.
Array in C# Array in C# RIHS Arshad Khan
Sections 10.1 – 10.4 Introduction to Arrays
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Passing Objects to Methods
Array ISYS 350.
Two-Dimensional Arrays
Chapter 10 Arrays.
Two Dimensional Array Mr. Jacobs.
Array, Strings and Vectors
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Foundations of Programming: Arrays
Java Arrays. Array Object An array :a container object holds a fixed number of values of a single type. The length of an array is established when the.
C++ Arrays.
Array ISYS 350.
Array ISYS 350.
Arrays Declare the Array of 100 elements Notes
Chapter 10 Arrays.
Visual Basic .NET BASICS
Chapter 6 Arrays.
Array ISYS 350.
Introduction to Processing Digital Sounds part 2
Array ISYS 350.
2D Arrays October 12, 2007 ComS 207: Programming I (in Java)
Why arrays are cool 4/25/2007.
Arrays .
Chapter 7 The Java Array Object © Rick Mercer.
Topics discussed in this section:
CS2011 Introduction to Programming I Arrays (I)
Arrays ICS2O.
Arrays.
Module8 Multi-dimensional Array
Arrays ICS2O.
Arrays Week 2.
CISC181 Introduction to Computer Science Dr
Arrays Part 2.
INC 161 , CPE 100 Computer Programming
Array ISYS 350.
Array ISYS 350.
Arrays, Casting & User Defined Variables
COS 151 Bootcamp – Week 4 Department of Computer Science
Week 7 - Monday CS 121.
Presentation transcript:

Java Array ISYS 350

Array An array allows you to store a group of items of the same type together. Processing a large number of items in an array is easier than processing a large number of items stored in separate variables.

Declaring a Array Examples of declaring an array: int[] anArray = new int[10]; 10 elements index from 0 to 9 double[] anArrayOfDoubles = new double[10]; String[] anArrayOfStrings = new String[10]; int[] anArray = { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};

Array Elements Array elements are indexed from 0 to array size – 1. Each element can be accessed by its index: arrayName[index] Ex: empName[0] intRate[2]

Array Initialization With the declaration statement: String[] empName = { "Peter", "Paul", "Mary" }; double[] intRate = { .03, .04, .05, .06, .07, .08 }; Initialize each element separately: empName[0] = "Peter"; empName[1] = "Paul"; empName[2] = "Mary";

Accessing Array Elements with a for loop Using array’s length property: for (arrayIndex = 0; arrayIndex <= empName.length-1; ++arrayIndex) { out.print(empName[arrayIndex]); } Note: length - 1

Example: Compute the sum and average of numbers in an array <% String[] stName = { "Peter", "Paul", "Mary", "Nancy", "Linda"}; double[] myGPAs = { 2.5, 3.2, 3.4, 2.9, 3.6 }; for (int arrayIndex = 0; arrayIndex <= stName.length-1; ++arrayIndex) { out.print(stName[arrayIndex] + ": GPA= " + myGPAs[arrayIndex]); out.print("<br>"); } double sumGPA=0, avgGPA; for (int i = 0; i <= myGPAs.length - 1; ++i) sumGPA += myGPAs[i]; avgGPA = sumGPA / myGPAs.length; out.print("Average GPA is: " + avgGPA); %>