Introduction To Programming Information Technology , 1’st Semester

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
 Pearson Education, Inc. All rights reserved Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 2: Major Concepts of Programming.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
 Pearson Education, Inc. All rights reserved Arrays.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Arrays.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
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.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
 2005 Pearson Education, Inc. All rights reserved Arrays.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Chapter 9 Introduction to Arrays Fundamentals of Java.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Array in C# Array in C# RIHS Arshad Khan
Arrays Chapter 7.
Presented By: Mahmoud Rafeek Alfarra
Two-Dimensional Arrays
Computer Programming BCT 1113
© 2016 Pearson Education, Ltd. All rights reserved.
Array, Strings and Vectors
Presented By: Mahmoud Rafeek Alfarra
JavaScript: Functions.
Arrays, For loop While loop Do while loop
Introduction To Programming Information Technology , 1’st Semester
Java How to Program, Late Objects Version, 10/e
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
7 Arrays.
2D Arrays October 12, 2007 ComS 207: Programming I (in Java)
EKT150 : Computer Programming
Object Oriented Programming in java
JavaScript Arrays.
Multidimensional Arrays
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
CS2011 Introduction to Programming I Arrays (I)
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Arrays Chapter 7.
Arrays Week 2.
7 Arrays.
Arrays in Java.
Introduction To Programming Information Technology , 1’st Semester
C++ Array 1.
Programming Fundamental
Presented By: Mahmoud Rafeek Alfarra
Arrays.
Presentation transcript:

Introduction To Programming Information Technology , 1’st Semester MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Using Java Introduction To Programming Information Technology , 1’st Semester Lecture 12,13 Arrays Teacher: Mahmoud Rafeek Alfarra

Outline Data types categories What is array and why? Declaring and Creating Arrays Examples Using Arrays Enhanced for Statement Example: Searching in array Example: Sorting array Multidimensional Arrays Emank X Mezank Presented & Prepared by: Mahmoud R. Alfarra

Data types categories In Programming, Types are divided into two categories Primitive types. int float char Reference types Object of any user-identified class Arrays Presented & Prepared by: Mahmoud R. Alfarra

What is array? Arrays are data structures consisting of related data items of the same type. Arrays are fixed-length entities they remain the same length once they are created(static data structure). Presented & Prepared by: Mahmoud R. Alfarra

What is array? Presented & Prepared by: Mahmoud R. Alfarra

Why array? An array is a group of variables (called elements or components) containing values that all have the same type. So, we can use it to store any related values and perform the operations on it as sorting, searching, printing , … Presented & Prepared by: Mahmoud R. Alfarra 6

Refers to elements in array A program refers to any one of these elements with an array-access expression that written as follow: Array [ i ] = k The name of array The value which assigns to the element The index of elements Begins from 0 to length-1 The first element in every array has index zero and is sometimes called the zeroth element. Presented & Prepared by: Mahmoud R. Alfarra

Declaring and Creating Arrays Arrays occupy space in memory. The programmer specifies the type of the elements and uses operator new to allocate dynamically the number of elements required by each array. Arrays are allocated with new because arrays are objects and all objects must be created with new. type[] array_name = new type[ x ]; Type of elements which will be allocated in the array Number of elements which will be allocated in the array Presented & Prepared by: Mahmoud R. Alfarra

Declaring and Creating Arrays int[] grades = new int[ 70 ]; String[] employees = new String[ 10 ]; float[] salary = new float[ 30 ]; Using a value of type long as an array index results in a compilation error. An index must be an int value or a value of a type that can be Presented & Prepared by: Mahmoud R. Alfarra

Be care In an array declaration, specifying the number of elements in the square brackets of the declaration (e.g., int c[ 12 ];) is a syntax error. Declaring multiple array variables in a single declaration can lead to subtle errors. Consider the declaration int[] a, b, c;. If a, b and c should be declared as array variables, then this declaration is correct placing square brackets directly following the type indicates that all the identifiers in the declaration are array variables. However, if only a is intended to be an array variable, and b and c are intended to be individual int variables, then this declaration is incorrect the declaration int a[], b, c; would achieve the desired result. Presented & Prepared by: Mahmoud R. Alfarra 10

Example1: Creating and Initializing an Array Presented & Prepared by: Mahmoud R. Alfarra 11

Example2: Creating and Initializing an Array Using an array initializer Presented & Prepared by: Mahmoud R. Alfarra 12

Example3: Creating and Initializing an Array Using an array initializer Presented & Prepared by: Mahmoud R. Alfarra 13

Example4: Calculating a Value to Store in Each Array Element Assigning a value to a constant after the variable has been initialized is a compilation error. Presented & Prepared by: Mahmoud R. Alfarra 14

Example5: Computing the sum of the elements of an array. Presented & Prepared by: Mahmoud R. Alfarra 15

for ( type arg : arrayName ) expression Enhanced for Statement Enhanced for iterates through the elements of an array or a collection without using a counter. The syntax of an enhanced for statement is: for ( type arg :  arrayName )           expression Presented & Prepared by: Mahmoud R. Alfarra 16

Example: Enhanced for Statement HW 12.1 Re-write all the previous examples using the enhanced for Presented & Prepared by: Mahmoud R. Alfarra 17

Example: Searching in array Presented & Prepared by: Mahmoud R. Alfarra

Example: Searching in array Presented & Prepared by: Mahmoud R. Alfarra

Example: Sorting an integer array HW 12.2 Write a program to sort a string array Presented & Prepared by: Mahmoud R. Alfarra 20

Multidimensional Arrays Multidimensional arrays with two dimensions are often used to represent tables of values consisting of information arranged in rows and columns. Presented & Prepared by: Mahmoud R. Alfarra 21

Creating Two-Dimensional Arrays Multidimensional arrays with two dimensions are often used to represent tables of values consisting of information arranged in rows and columns. Type array_name[ ][ ] = new type[ a ][ b ]; int array[ ][ ] = new int[ 3 ][ 4 ]; Presented & Prepared by: Mahmoud R. Alfarra 22

Emank X Mezank قال رسول الله صلى الله عليه وسلم: ( من دعا إلى هُدى كان له من الأجر مثل أجور من تَبِعَه لا ينقص ذلك من أجورهم شيئا) Presented & Prepared by: Mahmoud R. Alfarra

Next… Practices Presented & Prepared by: Mahmoud R. Alfarra