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)

PPT
JavaYDL6
Terry Yoast
 
PDF
javaarray
Arjun Shanka
 
PDF
Array
Scott Donald
 
PPT
Cso gaddis java_chapter8
mlrbrown
 
PDF
(2) collections algorithms
Nico Ludwig
 
PPT
ch06.ppt
AqeelAbbas94
 
PPT
ch06.ppt
ansariparveen06
 
PPT
array Details
shivas379526
 
PPT
ch06.ppt
chandrasekar529044
 
PPT
Pemrograman komputer 11 (array)
jayamartha
 
PDF
Arrays and library functions
Swarup Kumar Boro
 
PPTX
What-is-an-Array-in-Java-and-How-to-Create-One.pptx
manojsharma469262
 
PPT
Eo gaddis java_chapter_07_5e
Gina Bullock
 
PDF
LectureNotes-05-DSA
Haitham El-Ghareeb
 
PPT
17-Arrays en java presentación documento
DiegoGamboaSafla
 
PPT
9781111530532 ppt ch09
Terry Yoast
 
DOCX
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
ODP
(2) collections algorithms
Nico Ludwig
 
PPTX
Arrays in programming
TaseerRao
 
PPTX
Arrays
Trupti Agrawal
 
JavaYDL6
Terry Yoast
 
javaarray
Arjun Shanka
 
Cso gaddis java_chapter8
mlrbrown
 
(2) collections algorithms
Nico Ludwig
 
ch06.ppt
AqeelAbbas94
 
ch06.ppt
ansariparveen06
 
array Details
shivas379526
 
Pemrograman komputer 11 (array)
jayamartha
 
Arrays and library functions
Swarup Kumar Boro
 
What-is-an-Array-in-Java-and-How-to-Create-One.pptx
manojsharma469262
 
Eo gaddis java_chapter_07_5e
Gina Bullock
 
LectureNotes-05-DSA
Haitham El-Ghareeb
 
17-Arrays en java presentación documento
DiegoGamboaSafla
 
9781111530532 ppt ch09
Terry Yoast
 
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
(2) collections algorithms
Nico Ludwig
 
Arrays in programming
TaseerRao
 
Ad

Recently uploaded (20)

PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
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