SlideShare a Scribd company logo
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.
Arrays Class presentation
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

More Related Content

What's hot (20)

PPTX
Arrays in c
Jeeva Nanthini
 
PPTX
Array in C
Kamal Acharya
 
PPTX
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
PDF
An Introduction to Programming in Java: Arrays
Martin Chapman
 
PPTX
Arrays in java
Arzath Areeff
 
PPTX
Arrays C#
Raghuveer Guthikonda
 
PPT
Lec 25 - arrays-strings
Princess Sam
 
PPTX
Arrays in Java
Abhilash Nair
 
PPT
Mesics lecture 8 arrays in 'c'
eShikshak
 
PPTX
Array in c language
home
 
PPTX
Array in C# 3.5
Gopal Ji Singh
 
PPTX
Arrays in java language
Hareem Naz
 
PDF
Arrays in Java
Naz Abdalla
 
PPT
Array in Java
Shehrevar Davierwala
 
PPTX
Array,MULTI ARRAY, IN C
naveed jamali
 
PDF
Java Arrays
OXUS 20
 
PPT
One dimensional 2
Rajendran
 
PPTX
Array in c#
Prem Kumar Badri
 
PPT
Chap09
Terry Yoast
 
PPTX
Array in C
adityas29
 
Arrays in c
Jeeva Nanthini
 
Array in C
Kamal Acharya
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
An Introduction to Programming in Java: Arrays
Martin Chapman
 
Arrays in java
Arzath Areeff
 
Lec 25 - arrays-strings
Princess Sam
 
Arrays in Java
Abhilash Nair
 
Mesics lecture 8 arrays in 'c'
eShikshak
 
Array in c language
home
 
Array in C# 3.5
Gopal Ji Singh
 
Arrays in java language
Hareem Naz
 
Arrays in Java
Naz Abdalla
 
Array in Java
Shehrevar Davierwala
 
Array,MULTI ARRAY, IN C
naveed jamali
 
Java Arrays
OXUS 20
 
One dimensional 2
Rajendran
 
Array in c#
Prem Kumar Badri
 
Chap09
Terry Yoast
 
Array in C
adityas29
 

Similar to Arrays Class presentation (20)

PPTX
JAVA WORKSHOP(DAY 3) 1234567889999999.pptx
aniketraj4440
 
PPT
JavaYDL6
Terry Yoast
 
PPT
Cso gaddis java_chapter8
mlrbrown
 
PPTX
Introduction To Practical Computer Science I - Lec 12 (Arrays).pptx
AbdulKhaleqHerawi1
 
PPT
06slide
Dorothea Chaffin
 
PDF
Arrays in java
TharuniDiddekunta
 
PPT
05slide_arrays_creation_searching_sorting.ppt
ramesh504657
 
PPTX
Data Structures and Algorithoms 07slide - 1D Arrays.pptx
AliciaLee77
 
PPTX
Arrays in java.pptx
Nagaraju Pamarthi
 
PPTX
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
PDF
Java arrays (1)
Liza Abello
 
PPTX
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
fwzmypc2004
 
PPTX
CAP615-Unit1.pptx
SatyajeetGaur3
 
PPT
Array
PRN USM
 
PPTX
Create a Structure in VBNet.pptx
Breach_P
 
PPTX
Introduction to java
rishi ram khanal
 
PPT
07slide.ppt
NuurAxmed2
 
PPT
9781111530532 ppt ch09
Terry Yoast
 
PDF
Lecture 6
Debasish Pratihari
 
JAVA WORKSHOP(DAY 3) 1234567889999999.pptx
aniketraj4440
 
JavaYDL6
Terry Yoast
 
Cso gaddis java_chapter8
mlrbrown
 
Introduction To Practical Computer Science I - Lec 12 (Arrays).pptx
AbdulKhaleqHerawi1
 
Arrays in java
TharuniDiddekunta
 
05slide_arrays_creation_searching_sorting.ppt
ramesh504657
 
Data Structures and Algorithoms 07slide - 1D Arrays.pptx
AliciaLee77
 
Arrays in java.pptx
Nagaraju Pamarthi
 
arraylist in java a comparison of the array and arraylist
PriyadharshiniG41
 
Java arrays (1)
Liza Abello
 
JAVA INETRNSHIP1 made with simple topics.ppt.pptx
fwzmypc2004
 
CAP615-Unit1.pptx
SatyajeetGaur3
 
Array
PRN USM
 
Create a Structure in VBNet.pptx
Breach_P
 
Introduction to java
rishi ram khanal
 
07slide.ppt
NuurAxmed2
 
9781111530532 ppt ch09
Terry Yoast
 
Ad

Recently uploaded (20)

PPTX
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PPTX
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PPTX
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PDF
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
How to use _name_search() method in Odoo 18
Celine George
 
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
DLL english grade five goof for one week
FlordelynGonzales1
 
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
Wikinomics How Mass Collaboration Changes Everything Don Tapscott
wcsqyzf5909
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Ad

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.
  • 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