Java Programming: Program Design Including Data Structures. Chapter Objectives

Size: px
Start display at page:

Download "Java Programming: Program Design Including Data Structures. Chapter Objectives"

Transcription

1 Chapter 9: Arrays Java Programming: Program Design Including Data Structures Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of array index out of bounds Become familiar with the restrictions on array processing Discover how to pass an array as a parameter to a method Discover how to manipulate data in a two-dimensional array Learn about multidimensional arrays 2 1

2 Array A structured data type with a fixed number of components A 0 Data 1 Data Data Every component is of the same type Components are accessed using their relative positions in the array A[1] Length: 5 First index: 0 Last index: 4 3 One-Dimensional Arrays Syntax to instantiate an array: datatype[ ] arrayname; arrayname = new datatype[intexp] datatype[ ] arrayname = new datatype[intexp] datatype[ ] arrayname1, arrayname2; Example int[] A; A = new int[5]; int[] B = new int[5]; int[] C = {11, 22, 33, 44, 55; int[] E, F; 4 2

3 One-Dimensional Arrays Syntax to access an array component: arrayname[indexexp] intexp = number of components in array >= 0 0 <= indexexp <= intexp Example A[0] = 100; A[4] = 500; A[2] = A[4] A[0] + 1; A[5] = error (index out of bound) 5 Array num int[] num = new int[5]; 6 3

4 Array list 7 Default Values All entries of an array are first initialized to the proper data type default value. Example int[] A = new A[3]; Currently the array is A[0] = 0 A[1] = 0 A[2] = 0 Type int double boolean String Default Value false (empty) 8 4

5 Using Arrays int[] A; A = new int[5]; //all entries are set to zero int[] E, F; A[0] = 100; A[4] = 500; for (int i=0; i<a.length; i++) { System.out.println(i + " " + A[i]); E = A; //E same as A Specifying Array Size During Program Execution int arraysize; System.out.print("Enter the size of the array: "); arraysize = console.nextint(); int[] list = new int[arraysize];

6 Array Initialization During Declaration double[] sales = {12.25, 32.50, 16.90, 23, 45.68; The values, called initial values, are placed between braces and separated by commas sales[0]= 12.25, sales[1]= 32.50, etc. Array size is determined by the number of initial values within the braces If an array is declared and initialized simultaneously, do not use the operator new to instantiate the array object 11 Arrays and the Instance Variable length A public instance variable length is associated with each array that has been instantiated length contains the size of the array length can be directly accessed in a program using the array name and the dot operator Valid indices of an array (say A) are: 0 A.length - 1 Example: Here list.length is 6 int[] list = {10, 20, 30, 40, 50, 60; List[0] List[5] 12 6

7 Arrays and the Instance Variable length Create the array mylist of 10 components and initialize each component to 0 int[] mylist = new int[10]; The value of mylist.length is Arrays and the Instance Variable length (continued) These statements store 5, 10, 15, and 20, respectively, in the first four components of mylist mylist[0] = 5; mylist[1] = 10; mylist[2] = 15; mylist[3] = 20; Can store the number of filled elements, in the array in a variable, say noofelement 14 7

8 Processing One-Dimensional Arrays Loops used to step through elements in array and perform operations int[] list = new int[100]; int i; for (i = 0; i < list.length; i++) //process list[i], the (i + 1)th //element of list for (i = 0; i < list.length; i++) list[i] = console.nextint(); for (i = 0; i < list.length; i++) System.out.print(list[i] + " "); 15 Arrays Some operations on arrays: Initialize Input data Output stored data Find largest/smallest/sum/average of elements double[] sales = new double[10]; int index; double largestsale, sum, average; 16 8

9 Code to Initialize Array to Specific Value (10.00) for (index = 0; index < sales.length; index++) sales[index] = 10.00; 17 Code to Read Data into Array for (index = 0; index < sales.length; index++) sales[index] = console.nextdouble(); 18 9

10 Code to Print Array for (index = 0; index < sales.length; index++) System.out.print(sales[index] + " "); 19 Code to Find Sum and Average of Array sum = 0; for (index = 0; index < sales.length; index++) sum = sum + sales[index]; if (sales.length!= 0) average = sum / sales.length; else average = 0.0; 20 10

11 Determining Largest Element in Array maxindex = 0; for (index = 1; index < sales.length; index++) if (sales[maxindex] < sales[index]) maxindex = index; largestsale = sales[maxindex]; 21 Determining Largest Element in Array (continued) 22 11

12 Array Index Out of Bounds An array is in bounds if: 0 <= index <= arraysize 1 If index < 0 or index > arraysize: ArrayIndexOutOfBoundsException exception is thrown Base address: location of the first array component 23 Declaring Arrays as Formal Parameters to Methods General syntax to declare an array as a formal parameter: datatype[] arrayname //receiving the call from the caller public static void mymethod1 (int[] lista, double[] listb, int num) { //...do something here //making the call to a method int[] intlist = new int[10]; double[] doublemylist = new double[15]; int number; mymethod1 (intlist, doublemylist, number); 24 12

13 Declaring Arrays as Formal Parameters to Methods Example: Method is called with an array parameter //receiving the call from the caller public static void mymethod1 (int[] lista, double[] listb, int num) { //...do something here... //making the call to a method int[] intlist = {10, 20, 30, 40; Int[] mymethod1 (intlist, doublemylist, number); 25 Declaring Arrays as Formal Parameters to Methods Example: Method is called using an array parameter... int[] intlist = {10, 20, 30, 40; int listsize = intlist.length; mymethod1 (intlist, listsize); for (int i=0; i<listsize; i++) { System.out.println(i + " " + intlist[i]); private static void mymethod1(int[] A, int n) { for (int i=0; i<n; i++) { A[i] += 1; System.out.println(i + " " + A[i]);

14 The Assignment Operators and Arrays 27 The Assignment Operators and Arrays (continued) 28 14

15 The Assignment Operators and Arrays (continued) for (int index = 0; index < lista.length; index++) listb[index] = lista[index]; 29 Relational Operators Arrays if (lista == listb)... The expression lista == listb determines if the values of lista and listb are the same (refer to the same array) To determine whether lista and listb contain the same elements, compare them component by component You can write a method that returns true if two int arrays contain the same elements 30 15

16 Relational Operators and Arrays (continued) boolean isequalarrays(int[] firstarray, int[] secondarray) { if (firstarray.length!= secondarray.length) return false; for (int index = 0; index < firstarray.length; index++) if (firstarray[index]!= secondarray[index]) return false; return true; if (isequalarrays(lista, listb)) Methods for Array Processing //capture data from the keyboard public static void fillarray(int[] list, int noofelements) { int index; for (index = 0; index < noofelements; index++) list[index] = console.nextint(); 32 16

17 Methods for Array Processing (continued) public static void printarray(int[] list, int noofelements) { int index; for (index = 0; index < noofelements; index++) System.out.print(list[index] + " "); public static int sumarray(int[] list, int noofelements) { int index; int sum = 0; for (index = 0; index < noofelements; index++) sum = sum + list[index]; return sum; 33 Methods for Array Processing (continued) public static int indexlargestelement(int[] list, int noofelements) { int index; int maxindex = 0; for (index = 1; index < noofelements; index++) if (list[maxindex] < list[index]) maxindex = index; return maxindex; public static void copyarray(int[] list1, int[] list2, int noofelements) { int index; for (index = 0; index < noofelements; index++) list2[index] = list1[index]; 34 17

18 Parallel Arrays firstname lastname Arrays are parallel if the corresponding components hold related information Maria Macarena 3 Juan 3 Valdez 35 Arrays of Objects Can use arrays to manipulate objects Example: Create an array named array1 with N objects of type T: T[] array1 = new T[N] Can instantiate array1 as follows: for(int j=0; j <array1.length; j++) array1[j] = new T(); 36 18

19 Array of String Objects String[] namelist = new String[5]; namelist[0] = "Amanda Green"; namelist[1] = "Vijay Arora"; namelist[2] = "Sheila Mann"; namelist[3] = "Rohit Sharma"; namelist[4] = "Mandy Johnson"; 37 Array of String Objects (continued) 38 19

20 Arrays of Objects Clock[] arrivaltimeemp = new Clock[100]; 39 Instantiating Array Objects for (int j = 0; j < arrivaltimeemp.length; j++) arrivaltimeemp[j] = new Clock(); 40 20

21 Instantiating Array Objects arrivaltimeemp[49].settime(8, 5, 10); 41 Arrays and Variable Length Parameter List The syntax to declare a variable length formal parameter (list) is: datatype... identifier three dots It could be called using actual parameters such as mymethod (2, 4, 6, 1, 100, 3); mymethod (myarray); 42 21

22 Arrays and Variable Length Parameter List (continued) public static double largest(int... mylist) { double max; int index; if (mylist.length!= 0) { max = list[0]; for (index = 1; index < mylist.length; index++) { if (max < mylist [index]) max = mylist [index]; return max; return 0.0; Instead of: int[] mylist 43 Arrays and Variable Length Parameter List (continued) double num1 = largest(34, 56); double num2 = largest(12.56, 84, 92); double num3 = largest(98.32, 77, 64.67, 56); System.out.println(largest(22.50, 67.78, 92.58, 45, 34, 56)); double[] numberlist = {18. 50, 44, 56.23, , 112.0, 77, 11, 22, 86.62); System.out.println(largest(numberList)); 44 22

23 foreach loop The syntax to use for loop to process the elements of an array is: for (datatype identifier : arrayname) statements identifier is a variable, and the data type of identifier is the same as the data type of the array components 45 foreach loop sum = 0; for (double num : mydoublelist) sum = sum + num; The for statement is read for each num in list The identifier num is initialized to list[0] In the next iteration, the value of num is list[1], and so on 46 23

24 Two-Dimensional Arrays Data is sometimes in table form (difficult to represent using a one-dimensional array) To declare/instantiate a two-dimensional array: datatype[ ][ ] arrayname = new datatype[intexp1][intexp2]; int [][] dayhourtemperature = new int[31][25]; int [][] genderemployeedept = double int [2][10]; 47 Two-Dimensional Arrays To access a component of a two-dimensional array: arrayname[indexexp1][indexexp2]; intexp1, intexp2 >= 0 indexexp1 = row position indexexp2 = column position dayhourtemperature[01][01] = 41; dayhourtemperature[01][24] = 40; dayhourtemperature[30][24] = 38; 48 24

25 Two-Dimensional Arrays (continued) Can specify different number of columns for each row (ragged arrays) Three ways to process two-dimensional arrays: Entire array Particular row of array (row processing) Particular column of array (column processing) Processing algorithms is similar to processing algorithms of one-dimensional arrays 49 Two-Dimensional Arrays (continued) double[][]sales = new double[10][5]; 50 25

26 Accessing Two-Dimensional Array Components 51 Two-Dimensional Arrays: Special Cases 52 26

27 Two-Dimensional Arrays: Processing Initialization for (row = 0; row < matrix.length; row++) for (col = 0; col < matrix[row].length; col++) matrix[row][col] = 10; Print for (row = 0; row < matrix.length; row++) { for (col = 0; col < matrix[row].length; col++) System.out.printf("%7d", matrix[row][col]); System.out.println(); 53 Input Two-Dimensional Arrays: Processing (continued) for (row = 0; row < matrix.length; row++) for (col = 0; col < matrix[row].length; col++) matrix[row][col] = console.nextint(); Sum by Row for (row = 0; row < matrix.length; row++) { sum = 0; for (col = 0; col < matrix[row].length; col++) sum = sum + matrix[row][col]; System.out.println("Sum of row " + (row + 1) + " = "+ sum); 54 27

28 Sum by Column Two-Dimensional Arrays: Processing (continued) for (col = 0; col < matrix[0].length; col++) { sum = 0; for (row = 0; row < matrix.length; row++) sum = sum + matrix[row][col]; System.out.println("Sum of column " + (col + 1) + " = " + sum); 55 Two-Dimensional Arrays: Processing (continued) Largest Element in Each Row for (row = 0; row < matrix.length; row++) { largest = matrix[row][0]; for (col = 1; col < matrix[row].length; col++) if (largest < matrix[row][col]) largest = matrix[row][col]; System.out.println("The largest element of row " + (row + 1) + " = " + largest); 56 28

29 Two-Dimensional Arrays: Processing (continued) Largest Element in Each Column for (col = 0; col < matrix[0].length; col++) { largest = matrix[0][col]; for (row = 1; row < matrix.length; row++) if (largest < matrix[row][col]) largest = matrix[row][col]; System.out.println("The largest element of col " + (col + 1) + " = " + largest); 57 Multidimensional Arrays Can define three-dimensional arrays or n-dimensional arrays (n can be any number) Syntax to declare and instantiate array: datatype[][] [] arrayname = new datatype[intexp1][intexp2] [intexpn]; Syntax to access component: arrayname[indexexp1][indexexp2] [indexexpn] intexp1, intexp2,..., intexpn = positive integers indexexp1,indexexp2,..., indexexpn = non-negative integers 58 29

30 Loops to Process Multidimensional Arrays double[][][] cardealers = new double[10][5][7]; For (i = 0; i < 10; i++) for (j = 0; j < 5; j++) for (k = 0; k < 7; k++) cardealers[i][j][k] = 10.00; 59 Programming Example: Text Processing Program: Reads given text; outputs the text as is; prints number of lines and number of times each letter appears in text Input: File containing text to be processed Output: File containing text, number of lines, number of times each letter appears in text 60 30

31 Programming Example Solution: Text Processing An array of 26 representing the letters in the alphabet Three methods: copytext charactercount writetotal Value in appropriate index is incremented using methods and depends on character read from text 61 Chapter Summary Arrays Definition Uses Different arrays One-dimensional Two-dimensional Multidimensional (n-dimensional) Arrays of objects Parallel arrays 62 31

32 Chapter Summary (continued) Declaring arrays Instantiating arrays Processing arrays Entire array Row processing Column processing Common operations and methods performed on arrays Manipulating data in arrays 63 32

Spring 2010 Java Programming

Spring 2010 Java Programming Java Programming: Guided Learning with Early Objects Chapter 7 - Objectives Learn about arrays Explore how to declare and manipulate data in arrays Learn about the instance variable length Understand the

More information

Computer programming Code exercises [1D Array]

Computer programming Code exercises [1D Array] Computer programming-140111014 Code exercises [1D Array] Ex#1: //Program to read five numbers, from user. public class ArrayInput public static void main(string[] args) Scanner input = new Scanner(System.in);

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array Lesson Outcomes At the end of this chapter, student should be able to: Define array Understand requirement of array Know how to access elements of an array Write program using array Know how to pass array

More information

6. User Defined Functions I

6. User Defined Functions I 6 User Defined Functions I Functions are like building blocks They are often called modules They can be put togetherhe to form a larger program Predefined Functions To use a predefined function in your

More information

Arrays and the TOPICS CHAPTER 8. CONCEPT: An array can hold multiple values of the same data type simultaneously.

Arrays and the TOPICS CHAPTER 8. CONCEPT: An array can hold multiple values of the same data type simultaneously. CHAPTER 8 Arrays and the ArrayList Class TOPICS 8.1 Introduction to Arrays 8.2 Processing Array Elements 8.3 Passing Arrays As Arguments to Methods 8.4 Some Useful Array Algorithms and Operations 8.5 Returning

More information

Chapter 7 Multidimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 7 Multidimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Chapter 7 Multidimensional Arrays rights reserved. 1 Motivations Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent

More information

Computer Science is...

Computer Science is... Computer Science is... Machine Learning Machine learning is the study of computer algorithms that improve automatically through experience. Example: develop adaptive strategies for the control of epileptic

More information

CS1150 Principles of Computer Science Arrays

CS1150 Principles of Computer Science Arrays CS1150 Principles of Computer Science Arrays Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Read one hundred numbers, compute their

More information

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will: Chapter 8 Arrays and Strings Objectives In this chapter, you will: Learn about arrays Declare and manipulate data into arrays Learn about array index out of bounds Learn about the restrictions on array

More information

CS115 Principles of Computer Science

CS115 Principles of Computer Science CS5 Principles of Computer Science Chapter Arrays Prof. Joe X. Zhou Department of Computer Science CS5 Arrays. Re: Objectives in Methods To declare methods, invoke methods, and pass arguments to a method

More information

Chapter 7: Arrays and the ArrayList Class

Chapter 7: Arrays and the ArrayList Class Chapter 7: Arrays and the ArrayList Class Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 7 discusses the following main topics: Introduction

More information

Java-Array. This tutorial introduces how to declare array variables, create arrays, and process arrays using indexed variables.

Java-Array. This tutorial introduces how to declare array variables, create arrays, and process arrays using indexed variables. -Array Java provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful

More information

Chapter 7 Multidimensional Arrays

Chapter 7 Multidimensional Arrays Chapter 7 Multidimensional Arrays 1 Motivations You can use a two-dimensional array to represent a matrix or a table. Distance Table (in miles) Chicago Boston New York Atlanta Miami Dallas Houston Chicago

More information

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis Chapter 6: Arrays Starting Out with Games and Graphics in C++ Second Edition by Tony Gaddis 6.1 Array Basics An array allows you to store a group of items of the same data type together in memory Why?

More information

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals Arrays Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals Can we solve this problem? Consider the following program

More information

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017 Your Name: Exam 2. CSC 121 MW Class Lecturer: Howard Rosenthal April 26, 2017 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true

More information

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved 1 Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a table. For example, the following table that describes

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #07: September 21, 2015 1/30 We explained last time that an array is an ordered list of values. Each value is stored at a specific, numbered position in

More information

Chapter 9 Introduction to Arrays. Fundamentals of Java

Chapter 9 Introduction to Arrays. Fundamentals of Java Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced

More information

Module 5. Arrays. Adapted from Absolute Java, Rose Williams, Binghamton University

Module 5. Arrays. Adapted from Absolute Java, Rose Williams, Binghamton University Module 5 Arrays Adapted from Absolute Java, Rose Williams, Binghamton University Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type An

More information

Chapter 6. Arrays. Java Actually: A Comprehensive Primer in Programming

Chapter 6. Arrays. Java Actually: A Comprehensive Primer in Programming Lecture slides for: Chapter 6 Arrays Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 28. ISBN: 978-1-84448-933-2 http://www.ii.uib.no/~khalid/jac/

More information

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved 1 To describe why arrays are necessary in programming ( 6.1). To declare array reference variables and create arrays ( 6.2.1-6.2.2). To initialize the values in an array ( 6.2.3). To access array elements

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A

More information

Chapter 7 Single-Dimensional Arrays

Chapter 7 Single-Dimensional Arrays Chapter 7 Single-Dimensional Arrays 1 Arrays Array is a data structure that represents a collection of same-types data elements. A single-dimensional array is one that stores data elements in one row.

More information

Chapter 8 Multi-Dimensional Arrays

Chapter 8 Multi-Dimensional Arrays Chapter 8 Multi-Dimensional Arrays 1 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections of elements. myarray: 6 4 1 9 7 3 2 8 Now think

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

Multidimensional Arrays. CSE 114, Computer Science 1 Stony Brook University

Multidimensional Arrays. CSE 114, Computer Science 1 Stony Brook University Multidimensional Arrays CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Multidimensional Arrays How do we represent matrices or tables? A two-dimensional array

More information

Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen)

Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen) Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen) 1 Lesson 9: Introduction Objectives: To Arrays Write programs that handle collections of similar items. Declare

More information

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on:

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on: Arrays Arrays Arrays are objects that help us organize large amounts of information Chapter 7 focuses on: array declaration and use bounds checking and capacity arrays that store object references variable

More information

CS1150 Principles of Computer Science Arrays

CS1150 Principles of Computer Science Arrays CS1150 Principles of Computer Science Arrays Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Read one hundred numbers, compute their

More information

Chapter 7 Array. Array. C++, How to Program

Chapter 7 Array. Array. C++, How to Program Chapter 7 Array C++, How to Program Deitel & Deitel Spring 2016 CISC 1600 Yanjun Li 1 Array Arrays are data structures containing related data items of same type. An array is a consecutive group of memory

More information

Objectives. Chapter 8 Arrays and Strings. Objectives (cont d.) Introduction 12/14/2014. In this chapter, you will:

Objectives. Chapter 8 Arrays and Strings. Objectives (cont d.) Introduction 12/14/2014. In this chapter, you will: Objectives Chapter 8 Arrays and Strings In this chapter, you will: Learn about arrays Declare and manipulate data into arrays Learn about array index out of bounds Learn about the restrictions on array

More information

15. Multidimensional Arrays

15. Multidimensional Arrays 15. Multidimensional Arrays Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Declaring and Creating of Two-Dimensional Arrays Ragged Arrays Simple Processing on Two-Dimensional Arrays Three-Dimensional

More information

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Announcements PS 4 is ready, due next Thursday, 9:00pm Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Room TBD Scope: Lecture 1 to Lecture 9 (Chapters 1 to 6 of text) You may bring a sheet of paper (A4, both

More information

Chapter 8 Multidimensional Arrays

Chapter 8 Multidimensional Arrays Chapter 8 Multidimensional Arrays 8.1 Introduction Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a

More information

Java Arrays. What could go wrong here? Motivation. Array Definition 9/28/18. Mohammad Ghafari

Java Arrays. What could go wrong here? Motivation. Array Definition 9/28/18. Mohammad Ghafari 9/28/8 Java Arrays What could go wrong here? int table[][] = new int[2][]; // some code int sum = ; for (int i = ; i < 2; i++) for (int j = ; j < ; j++) int value = table[i][j]; sum += value; Mohammad

More information

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops. CSE 114, Computer Science 1 Stony Brook University Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?

More information

Module 7: Arrays (Single Dimensional)

Module 7: Arrays (Single Dimensional) Module 7: Arrays (Single Dimensional) Objectives To describe why arrays are necessary in programming ( 7.1). To declare array reference variables and create arrays ( 7.2.1 7.2.2). To obtain array size

More information

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202

More information

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY Objectives Declaration of 1-D and 2-D Arrays Initialization of arrays Inputting array elements Accessing array elements Manipulation

More information

Object Oriented Programming. Java-Lecture 6 - Arrays

Object Oriented Programming. Java-Lecture 6 - Arrays Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types

More information

Arrays. Lecture 11 CGS 3416 Fall October 26, 2015

Arrays. Lecture 11 CGS 3416 Fall October 26, 2015 Arrays Lecture 11 CGS 3416 Fall 2015 October 26, 2015 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed means that the array elements are numbered (starting

More information

Instructor: Eng.Omar Al-Nahal

Instructor: Eng.Omar Al-Nahal Faculty of Engineering & Information Technology Software Engineering Department Computer Science [2] Lab 6: Introduction in arrays Declaring and Creating Arrays Multidimensional Arrays Instructor: Eng.Omar

More information

Arrays. Eng. Mohammed Abdualal

Arrays. Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays

More information

Arrays. Introduction to OOP with Java. Lecture 06: Introduction to OOP with Java - AKF Sep AbuKhleiF - 1

Arrays. Introduction to OOP with Java. Lecture 06: Introduction to OOP with Java - AKF Sep AbuKhleiF -  1 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 06: Arrays Instructor: AbuKhleif, Mohammad Noor Sep 2017 AbuKhleiF - 1 Instructor AbuKhleif, Mohammad Noor Computer Engineer

More information

Arrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19

Arrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19 Arrays Lecture 11 CGS 3416 Spring 2017 March 6, 2017 Lecture 11CGS 3416 Spring 2017 Arrays March 6, 2017 1 / 19 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed

More information

array Indexed same type

array Indexed same type ARRAYS Spring 2019 ARRAY BASICS An array is an indexed collection of data elements of the same type Indexed means that the elements are numbered (starting at 0) The restriction of the same type is important,

More information

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016

Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016 Your Name: Exam 2. CSC 121 MW Class Lecturer: Howard Rosenthal April 25, 2016 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true

More information

Two Dimensional Arrays

Two Dimensional Arrays + Two Dimensional Arrays + Two Dimensional Arrays So far we have studied how to store linear collections of data using a single dimensional array. However, the data associated with certain systems (a digital

More information

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7] Arrays Arrays deal with storage of data, which can be processed later. Arrays are a series of elements (variables) of the same type placed consecutively in memory that can be individually referenced by

More information

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it Last Class Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it public class February4{ public static void main(string[] args) { String[]

More information

HST 952. Computing for Biomedical Scientists Lecture 5

HST 952. Computing for Biomedical Scientists Lecture 5 Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 5 Outline Recursion and iteration Imperative and

More information

AP Computer Science A Unit 7. Notes on Arrays

AP Computer Science A Unit 7. Notes on Arrays AP Computer Science A Unit 7. Notes on Arrays Arrays. An array is an object that consists of an of similar items. An array has a single name and the items in an array are referred to in terms of their

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 1D & 2D Arrays Multiple Choice Test 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. Chapter 6 Single-Dimensional Arrays rights reserved. 1 Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average. Solution AnalyzeNumbers rights

More information

Opening Problem EXAMPLE. 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average.

Opening Problem EXAMPLE. 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average. Chapter 6 Arrays 1 Opening Problem EXAMPLE 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average. 2 Introducing Arrays Array is a data structure

More information

Java Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Java Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying Java Software Solutions

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays Methods 3 A method: groups a sequence of statement takes input, performs actions, and

More information

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 Date: 01/18/2011 (Due date: 01/20/2011) Name and ID (print): CHAPTER 6 USER-DEFINED FUNCTIONS I 1. The C++ function pow has parameters.

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Arrays WIT COMP1000 Arrays Arrays An array is a list of variables of the same type, that represents a set of related values For example, say you need to keep track of the cost of 1000 items You could declare

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 2 3 CMPE 013/L and Strings Gabriel Hugh Elkaim Spring 2013 4 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are

More information

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17 CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays 1 Methods : Method Declaration: Header 3 A method declaration begins with a method header

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Arrays A data structure for a collection of data that is all of the same data type. The data type can be

More information

Last Class. More on loops break continue A bit on arrays

Last Class. More on loops break continue A bit on arrays Last Class More on loops break continue A bit on arrays public class February2{ public static void main(string[] args) { String[] allsubjects = { ReviewArray, Example + arrays, obo errors, 2darrays };

More information

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof Array Lecture 12 Based on Slides of Dr. Norazah Yusof 1 Introducing Arrays Array is a data structure that represents a collection of the same types of data. In Java, array is an object that can store a

More information

COE 212 Engineering Programming. Welcome to the Final Exam Monday May 18, 2015

COE 212 Engineering Programming. Welcome to the Final Exam Monday May 18, 2015 1 COE 212 Engineering Programming Welcome to the Final Exam Monday May 18, 2015 Instructors: Dr. Joe Tekli Dr. George Sakr Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.

More information

IST 297D Introduction to Application Programming Chapter 4 Problem Set. Name:

IST 297D Introduction to Application Programming Chapter 4 Problem Set. Name: IST 297D Introduction to Application Programming Chapter 4 Problem Set Name: 1. Write a Java program to compute the value of an investment over a number of years. Prompt the user to enter the amount of

More information

Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class

Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class Section 6.10 Two Dimensional Arrays 1. The arrays we have studied so far are one dimensional arrays, which we usually just call arrays. Twodimensional

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Language Reference Manual

Language Reference Manual ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents

More information

CS171:Introduction to Computer Science II

CS171:Introduction to Computer Science II CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 9/7/2012 1 Announcement Introductory/Eclipse Lab, Friday, Sep 7, 2-3pm (today) Hw1 to be assigned Monday,

More information

Computer Science 1 Honors

Computer Science 1 Honors Computer Science 1 Honors Will be Most methods are too complex simply to call them and let them do their job. Methods almost always need more information. For example, a method that finds a square root,

More information

Chapter 6. Arrays. Array Basics Arrays in Classes and Methods Programming with Arrays and Classes Sorting Arrays Multidimensional Arrays

Chapter 6. Arrays. Array Basics Arrays in Classes and Methods Programming with Arrays and Classes Sorting Arrays Multidimensional Arrays Chapter 6 Arrays Array Basics Arrays in Classes and Methods Programming with Arrays and Classes Sorting Arrays Multidimensional Arrays Chapter 6 Java: an Introduction to Computer Science & Programming

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection

More information

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

Arrays in Java Using Arrays

Arrays in Java Using Arrays Recall Length of an Array Arrays in Java Using Arrays Once an array has been created in memory, its size is fixed for the duration of its existence. Every array object has a length field whose value can

More information

www.thestudycampus.com Methods Let s imagine an automobile factory. When an automobile is manufactured, it is not made from basic raw materials; it is put together from previously manufactured parts. Some

More information

Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal

Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Review what an array is Review how to declare arrays Review what reference variables are Review how to pass arrays to methods Review

More information

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays: College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 11 Arrays: A. Write a code snippet to define the following arrays: 1. An int array named nums of size 10.

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 10 For Loops and Arrays Outline Problem: How can I perform the same operations a fixed number of times? Considering for loops Performs same operations

More information

CMPT 126: Lecture 6 Arrays

CMPT 126: Lecture 6 Arrays CMPT 126: Lecture 6 Arrays Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University September 25, 2007 1 Array Elements An array is a construct used to group and organize data.

More information

Array Basics: Outline

Array Basics: Outline Arrays Chapter 7 Array Basics: Outline Creating and Accessing Arrays Array Details The Instance Variable length More About Array Indices Partially-filled Arrays Working with Arrays Creating and Accessing

More information

Lecture 17. For Array Class Shenanigans

Lecture 17. For Array Class Shenanigans Lecture 17 For Array Class Shenanigans For or While? class WhileDemo { public static void main(string[] args){ int count = 1; while (count < 11) { System.out.println("Count is: " + count); count++; Note:

More information

Example: Computing prime numbers

Example: Computing prime numbers Example: Computing prime numbers -Write a program that lists all of the prime numbers from 1 to 10,000. Remember a prime number is a # that is divisible only by 1 and itself Suggestion: It probably will

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1 self-check: Ch. 4 #2; Ch. 5 # 1-10 exercises: Ch. 4 #2, 4, 5, 8; Ch. 5 # 1-2 Copyright 2009

More information

Chapter 6 SINGLE-DIMENSIONAL ARRAYS

Chapter 6 SINGLE-DIMENSIONAL ARRAYS Chapter 6 SINGLE-DIMENSIONAL ARRAYS Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk What is an Array? A single array variable can reference

More information

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays

More information

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

BITG 1113: Array (Part 1) LECTURE 8

BITG 1113: Array (Part 1) LECTURE 8 BITG 1113: Array (Part 1) LECTURE 8 1 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of arrays 2. Describe the types of array: One Dimensional (1 D)

More information

Arrays CHAPTER. 6.1 INTRODUCTION TO ARRAYS 338 Creating and Accessing Arrays 339 The length Instance Variable 342 Initializing Arrays 345

Arrays CHAPTER. 6.1 INTRODUCTION TO ARRAYS 338 Creating and Accessing Arrays 339 The length Instance Variable 342 Initializing Arrays 345 CHAPTER 6 Arrays 6.1 INTRODUCTION TO ARRAYS 338 Creating and Accessing Arrays 339 The length Instance Variable 342 Initializing Arrays 345 6.2 ARRAYS AND REFERENCES 348 Arrays Are Objects 348 Array Parameters

More information

2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier

2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier Lesson 4 Arrays and Lists Review CSC 123 Fall 2018 Answer Sheet Short Answers 1. In an array declaration, this indicates the number of elements that the array will have. b a. subscript b. size declarator

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Tutorial about Arrays

Tutorial about Arrays Q1: Write Java statements that do the following: Reviewed Tutorial about Arrays a. Declare an array alpha of 15 components of the type int int alpha[] = new int[15]; b. Print the value of the tenth component

More information

Chapter 7 User-Defined Methods. Chapter Objectives

Chapter 7 User-Defined Methods. Chapter Objectives Chapter 7 User-Defined Methods Chapter Objectives Understand how methods are used in Java programming Learn about standard (predefined) methods and discover how to use them in a program Learn about user-defined

More information

Lesson 35..Two-Dimensional Arrays

Lesson 35..Two-Dimensional Arrays Lesson 35..Two-Dimensional Arrays 35-1 Consider the following array (3 rows, 2 columns) of numbers: 22 23 24 25 26 27 Let s declare our array as follows: int a[ ] [ ] = new int [3] [2]; Subscript convention:

More information