SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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)Imdadul Himu
 
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: ArraysMartin Chapman
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-stringsPrincess Sam
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'eShikshak
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java languageHareem Naz
 
Array,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN CArray,MULTI ARRAY, IN C
Array,MULTI ARRAY, IN Cnaveed jamali
 
Java Arrays
Java ArraysJava Arrays
Java ArraysOXUS 20
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 

Mais procurados (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
 

Semelhante a Arrays Class presentation

Semelhante a 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)
 
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
 
Pi j3.4 data-structures
Pi j3.4 data-structuresPi j3.4 data-structures
Pi j3.4 data-structures
 

Último

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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 Delhikauryashika82
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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 pdfAyushMahapatra5
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Último (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

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