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

PDF
intorduction to Arrays in java
PPT
Java Arrays
PPSX
C Programming : Arrays
PPTX
Array lecture
PPTX
Java arrays
PDF
Lecture17 arrays.ppt
PPTX
PPTX
Array in c++
intorduction to Arrays in java
Java Arrays
C Programming : Arrays
Array lecture
Java arrays
Lecture17 arrays.ppt
Array in c++

What's hot (20)

PPTX
Arrays in c
PPTX
Array in C
PPTX
A Presentation About Array Manipulation(Insertion & Deletion in an array)
PDF
An Introduction to Programming in Java: Arrays
PPTX
Arrays in java
PPTX
PPT
Lec 25 - arrays-strings
PPTX
Arrays in Java
PPT
Mesics lecture 8 arrays in 'c'
PPTX
Array in c language
PPTX
Array in C# 3.5
PPTX
Arrays in java language
PDF
Arrays in Java
PPT
Array in Java
PPTX
Array,MULTI ARRAY, IN C
PDF
Java Arrays
PPT
One dimensional 2
PPTX
Array in c#
PPT
Chap09
PPTX
Array in C
Arrays in c
Array in C
A Presentation About Array Manipulation(Insertion & Deletion in an array)
An Introduction to Programming in Java: Arrays
Arrays in java
Lec 25 - arrays-strings
Arrays in Java
Mesics lecture 8 arrays in 'c'
Array in c language
Array in C# 3.5
Arrays in java language
Arrays in Java
Array in Java
Array,MULTI ARRAY, IN C
Java Arrays
One dimensional 2
Array in c#
Chap09
Array in C
Ad

Similar to Arrays Class presentation (20)

PPT
JavaYDL6
PDF
javaarray
PDF
PPT
Cso gaddis java_chapter8
PDF
(2) collections algorithms
PPT
ch06.ppt
PPT
PPT
ch06.ppt
PPT
array Details
PPT
Pemrograman komputer 11 (array)
PDF
Arrays and library functions
PPTX
What-is-an-Array-in-Java-and-How-to-Create-One.pptx
PPT
Eo gaddis java_chapter_07_5e
PDF
LectureNotes-05-DSA
PPT
17-Arrays en java presentación documento
PPT
9781111530532 ppt ch09
DOCX
Class notes(week 4) on arrays and strings
ODP
(2) collections algorithms
PPTX
Arrays in programming
PPTX
JavaYDL6
javaarray
Cso gaddis java_chapter8
(2) collections algorithms
ch06.ppt
ch06.ppt
array Details
Pemrograman komputer 11 (array)
Arrays and library functions
What-is-an-Array-in-Java-and-How-to-Create-One.pptx
Eo gaddis java_chapter_07_5e
LectureNotes-05-DSA
17-Arrays en java presentación documento
9781111530532 ppt ch09
Class notes(week 4) on arrays and strings
(2) collections algorithms
Arrays in programming
Ad

Recently uploaded (20)

PPTX
IMMUNIZATION PROGRAMME pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
High Ground Student Revision Booklet Preview
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
PDF
English Language Teaching from Post-.pdf
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Congenital Hypothyroidism pptx
PPTX
Onica Farming 24rsclub profitable farm business
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
IMMUNIZATION PROGRAMME pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
High Ground Student Revision Booklet Preview
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
English Language Teaching from Post-.pdf
UPPER GASTRO INTESTINAL DISORDER.docx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Abdominal Access Techniques with Prof. Dr. R K Mishra
NOI Hackathon - Summer Edition - GreenThumber.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
Congenital Hypothyroidism pptx
Onica Farming 24rsclub profitable farm business
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Insiders guide to clinical Medicine.pdf
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Software Engineering BSC DS UNIT 1 .pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Open Quiz Monsoon Mind Game Final Set.pptx
How to Manage Loyalty Points in Odoo 18 Sales

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