SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Introduction to Computer Programming
               Lab 2




          Arrays

            Neveen Reda
Arrays in action
0 There are many uses for arrays
0 For example image pixels are represented using
 arrays




                      Neuroph (2012)
Arrays in action

                0 Arrays can also be used
                 in creating grids for
                 games.




Eckert (2009)
Lesson Objectives
After this lesson you will be able to:

3.Develop Java programs that create arrays and perform
different operations on them.

5.Determine the functionality and output of any given
program that performs array manipulations.
Arrays
0 Why arrays?
    Individual variables can only hold one value at a time, Arrays
     can holds multiple values (Abdennadher , 2010).
0 “An array is a data structure that defines an indexed
  collection of a fixed number of data elements.” (Mughal &
  Rasmussen, 2009).
Arrays
0 The position of an element in an array is called the index.
0 If array X contains 10 elements, the first element will be at
 position (index) '0' and the last element is at position '9'




                            Oracle (2012)
Arrays Declarations
0 All the elements in an array have the same data type.
(For example all integers, all Strings, all doubles and so on)

Examples:


int [] x;        //x is an array of integers.
double [] myArray;    //myArray is an array of doubles.
Creating Arrays
0 The size if an array is fixed. It is specified when the array is
  created and cannot be changed (Abdennadher , 2010).




x = new int[5];        //array x is now of size 5
myArray = new double[3];
Creating Arrays
0 An array can be declared and created in one statement.
0 Until this point the arrays is empty (contains default values
  of its declared type)

Examples:

int [] x = new int [5];
double [] myArray = new double [3];
int number = 10;
char [] letters = new char[number];
Initializing Arrays
Double [] prices = new double [5];
Initializing Arrays
Double [] prices = {2.25, 3.0, 10.5, 5.3, 0.5};




                                                  2.25
                                                  3.0

                                                  10.5

                                                  5.3

                                                  0.5
Using Arrays
After creating and initializing an array, it can be used
    within a program:


•     An element in the array can be used within a
     statement
•    The reference to the array can be used within a
     statement. (Abdennadher , 2010)
Using Arrays
0 Reassign value to index:
                                           4.5
                                           2.25
                        Prices[0] = 4.5;
                                           3.0
                                           10.5

                                           5.3

                                           0.5
0 Using element within a statement:

if(Prices[1] >= 3.0){
Discount = 10;
}
Array Examples

0 Write a java program that creates an array of size 3 and
 prints all its elements using a for loop.
References
•   Abdennadher S. (2010). Arrays. Lecture notes.

•   Eckert T. (2009). Bimaru - Battleship Solitaire [image]. Retrieved from:
    http://www.cyrket.com/p/android/com.androidcan.bimaru/

•   Mughal K. A. & Rasmussen R. W. (2009). A Programmer's Guide to Java SCJP
    Certification. Upper Saddle River, NJ: Pearson Education.

•   Neuroph (2012). Image colors [image]. Retrieved from: http://
    neuroph.sourceforge.net/image_recognition.html

•   Oracle (2012). An array of 10 elements [image]. Retrieved from: http
    ://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Weitere ähnliche Inhalte

Was ist angesagt?

Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 

Was ist angesagt? (20)

Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in C
Array in CArray in C
Array in C
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN C
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Array in c#
Array in c#Array in c#
Array in c#
 
Chap09
Chap09Chap09
Chap09
 
Array in C
Array in CArray in C
Array in C
 

Ähnlich wie Arrays Class presentation

Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
mlrbrown
 
9781111530532 ppt ch09
9781111530532 ppt ch099781111530532 ppt ch09
9781111530532 ppt ch09
Terry Yoast
 

Ähnlich wie Arrays Class presentation (20)

JavaYDL6
JavaYDL6JavaYDL6
JavaYDL6
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
 
06slide
06slide06slide
06slide
 
Arrays
ArraysArrays
Arrays
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays in java.pptx
Arrays in java.pptxArrays in java.pptx
Arrays in java.pptx
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
JAVA INETRNSHIP1 made with simple topics.ppt.pptxJAVA INETRNSHIP1 made with simple topics.ppt.pptx
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Array
ArrayArray
Array
 
Create a Structure in VBNet.pptx
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
9781111530532 ppt ch09
9781111530532 ppt ch099781111530532 ppt ch09
9781111530532 ppt ch09
 
Lecture 6
Lecture 6Lecture 6
Lecture 6
 
Advanced Programming Lecture 6 Fall 2016
Advanced Programming Lecture 6 Fall 2016Advanced Programming Lecture 6 Fall 2016
Advanced Programming Lecture 6 Fall 2016
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Arrays Class presentation

  • 1. Introduction to Computer Programming Lab 2 Arrays Neveen Reda
  • 2. Arrays in action 0 There are many uses for arrays 0 For example image pixels are represented using arrays Neuroph (2012)
  • 3. Arrays in action 0 Arrays can also be used in creating grids for games. Eckert (2009)
  • 4. Lesson Objectives After this lesson you will be able to: 3.Develop Java programs that create arrays and perform different operations on them. 5.Determine the functionality and output of any given program that performs array manipulations.
  • 5. Arrays 0 Why arrays?  Individual variables can only hold one value at a time, Arrays can holds multiple values (Abdennadher , 2010). 0 “An array is a data structure that defines an indexed collection of a fixed number of data elements.” (Mughal & Rasmussen, 2009).
  • 6. Arrays 0 The position of an element in an array is called the index. 0 If array X contains 10 elements, the first element will be at position (index) '0' and the last element is at position '9' Oracle (2012)
  • 7. Arrays Declarations 0 All the elements in an array have the same data type. (For example all integers, all Strings, all doubles and so on) Examples: int [] x; //x is an array of integers. double [] myArray; //myArray is an array of doubles.
  • 8. Creating Arrays 0 The size if an array is fixed. It is specified when the array is created and cannot be changed (Abdennadher , 2010). x = new int[5]; //array x is now of size 5 myArray = new double[3];
  • 9. Creating Arrays 0 An array can be declared and created in one statement. 0 Until this point the arrays is empty (contains default values of its declared type) Examples: int [] x = new int [5]; double [] myArray = new double [3]; int number = 10; char [] letters = new char[number];
  • 10. Initializing Arrays Double [] prices = new double [5];
  • 11. Initializing Arrays Double [] prices = {2.25, 3.0, 10.5, 5.3, 0.5}; 2.25 3.0 10.5 5.3 0.5
  • 12. Using Arrays After creating and initializing an array, it can be used within a program: • An element in the array can be used within a statement • The reference to the array can be used within a statement. (Abdennadher , 2010)
  • 13. Using Arrays 0 Reassign value to index: 4.5 2.25 Prices[0] = 4.5; 3.0 10.5 5.3 0.5 0 Using element within a statement: if(Prices[1] >= 3.0){ Discount = 10; }
  • 14. Array Examples 0 Write a java program that creates an array of size 3 and prints all its elements using a for loop.
  • 15.
  • 16. References • Abdennadher S. (2010). Arrays. Lecture notes. • Eckert T. (2009). Bimaru - Battleship Solitaire [image]. Retrieved from: http://www.cyrket.com/p/android/com.androidcan.bimaru/ • Mughal K. A. & Rasmussen R. W. (2009). A Programmer's Guide to Java SCJP Certification. Upper Saddle River, NJ: Pearson Education. • Neuroph (2012). Image colors [image]. Retrieved from: http:// neuroph.sourceforge.net/image_recognition.html • Oracle (2012). An array of 10 elements [image]. Retrieved from: http ://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html