03/16/101. 2 What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.

Slides:



Advertisements
Similar presentations
IS Programming Fundamentals 1 (Lec) Date: September 14, Array.
Advertisements

Chapter 8: Arrays.
Arrays.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
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.
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.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
Introduction to arrays Data in economy size packages.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
Java Syntax Primitive data types Operators Control statements.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Lecture 5 Arrays A way to organize data © MIT AITI 2003.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Java Unit 9: Arrays Declaring and Processing Arrays.
The University of Texas – Pan American
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
French Territory of St. Pierre CSE 114 – Computer Science I Arrays.
1 Lecture # 4. * An array is a group of contiguous or related data items that share a common name. * Each value is stored at a specific position * Position.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
Lecturer : Sakuni Sellapperuma. Introduction An array is a container object that holds a fixed number of values of a single type. The length of an array.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
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.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
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.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Array Objectives To understand the concept of arrays To understand the purpose to which we use arrays. To be able to declare references to arrays. To be.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 7.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Arrays.
1. Define an array 1 Create reference arrays of objects in Java program 2 Initialize elements of arrays 3 Pass array to methods 4 Return array to methods.
Introduction to Computing Concepts Note Set 21. Arrays Declaring Initializing Accessing Using with Loops Sending to methods.
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
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.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Grouping Data Together Often we want to group together a number of values or objects to be treated in the same way e.g. names of students in a tutorial.
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.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
Array and String.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
CMSC 150 ARRAYS CS 150: Fri 10 Feb Motivation  Consider a list of your contact addresses: String Zero = String.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to programming in java Lecture 21 Arrays – Part 1.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Chapter 8 Arrays and the ArrayList Class Arrays of Objects.
Array in C# Array in C# RIHS Arshad Khan
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.
An Introduction to Java – Part I, language basics
EKT150 : Computer Programming
Introduction To Programming Information Technology , 1’st Semester
Topics discussed in this section:
MSIS 655 Advanced Business Applications Programming
class PrintOnetoTen { public static void main(String args[]) {
Arrays Week 2.
Single-Dimensional Arrays chapter6
Arrays in Java.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Presentation transcript:

03/16/101

2 What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics of Arrays, - All the array elements should be in same type - Arrays have a fixed length. They cannot be expanded or shrunk. - Elements of the array are accessed by the index

03/16/103 Declaring one Dimensional Arrays... data_type array_name[]; or data_type[] array; Data type indicates the type of the elements that are going to be stored. Ex: int arr[]; String arr[]; char arr[]; float arr[];

02/10/104 Initialize 1D arrays... Method 1: The arrays are initialized by using the ‘new’ keyword. The number of elements that the array will hold should be specified. int arr[]=new int[5]; arr[0]=10; arr[3]=56;

02/10/105 Initialize 1D arrays (Cont)... Method 2: The array can be initialized by specifying the elements in the array. int arr[]={12, 78, 65, 90, 10};

03/16/106 Passing 1D arrays to methods... class ArrayExample { void calculate(int arr[]) { for(int i=0;i<5;i++)‏ { System.out.println(arr[i]); } class ArrayExample { void calculate(int arr[]) { for(int i=0;i<5;i++)‏ { System.out.println(arr[i]); } Calling Statement: int num[]={4,6,8,1,4}; ArrayExample arr=new ArrayExample(); arr.calculate(num); Calling Statement: int num[]={4,6,8,1,4}; ArrayExample arr=new ArrayExample(); arr.calculate(num);

02/10/107 Array of Objects... Arrays not only hold the elements with primitive data types. They can also hold the objects. Ex: Suppose there are 5 students in a class. Student stu[]=new Student[5];

03/16/108 Example... Suppose that there are 5 students in a class in a school. Modify the Example2 (Student Example) to hold the information of 5 students using an array. class Example2 { public static void main(String arg[]) { Student stu[]=new Student[5]; stu[i].age=10; } class Example2 { public static void main(String arg[]) { Student stu[]=new Student[5]; stu[i].age=10; }

9 Example... Write a JAVA program to store the information of two students. Each student have a Age, Gender, Marks for mathematics, Marks for statistics, Marks for computer science and average of three subjects. AttributeStudent 1Student 2 Age 2123 GenderFM Marks for Mathematics6789 Marks for Statistics7654 Marks for Computer Science7895

03/16/1010 Declaring two Dimensional Arrays... data_type array_name[][]; or data_type[][] array; Data type indicates the type of the elements that are going to be stored. Ex: int arr[][]; String arr[][]; char arr[][]; float arr[][];

02/10/1011 Initialize 2D arrays... Method 1: The arrays are initialized by using the ‘new’ keyword. The number of elements that the array will hold must be specified. int arr[]=new int[3][5]; arr[1][1]=10;

02/10/1012 Initialize arrays (Cont)... Method 2: The array is initialized by specifying the elements in the array. int arr[][]={{12, 78,54}, {65, 90,22}, {10,8,11}, {3,9,15}, {8,1,90}};

03/16/1013 Example... Create a multiplication table using 2D array.