You are on page 1of 29

Click to edit Master title style

Java OOP – Arrays

1
Lesson Topics
Click to edit Master title style

1. Arrays
2. Declaring Arrays
3. Accessing Array Elements
4. Activity

2 2
ARRAYS
Click to edit Master title style

Is a Collection of multiple values in a Single


Variable with the Same Data type.
They are governed by using index.

3 3
Click to edit Master title style

4 4
ELEMENTS
Click to edit Master title style

Are the Individual values in an Array.

5 5
Declaring Arrays
Click to edit Master title style

Declare w/ values
datatype identifier[]={val1,val2,val3, val4};
String names[]={“Mark”, “Leslie” , “John” , “Jason”, “Mike”};

6 6
Click to edit Master title style

7 7
Click to edit Master title style

8 8
Declaring Arrays
Click to edit Master title style

Declare w/o values


datatype identifier[]=new datatype[size];
String names[]=new String[4];

9 9
Click to edit Master title style

10 10
INDEX
Click to edit Master title style

Is a number that represents a position in a


collection.

11 11
Accessing Array
Click to edit Master title style

VALUE “Mark” “Leslie” “John” “Juan”


INDEX 0 1 2 3

12 12
Accessing Array
Click to edit Master title style

Reading Array Element


identifier[index];
names[0];

13 13
Click to edit Master title style

14 14
Click to edit Master title style

15 15
Accessing Array
Click to edit Master title style

Assigning Array Element


identifier[index] = value;
names[0] = “Marcos”;

16 16
Click to edit Master title style

17 17
Click to edit Master title style

18 18
Accessing Array
Click to edit Master title style

Assigning Array Element w/ User Input


Scanner s = new Scanner(System.in);
names[0] = s.nextLine();

19 19
Click to edit Master title style

20 20
Click to edit Master title style

21 21
Click to edit Master title style

LESSON
ACTIVITY

22
Paired Arrays by Index
Click to edit Master title style

Create 3 arrays that will hold 5 user’s credentials:


• Email
• Username
• Password
For example : email[0], username[0], and password[0]
should belong to the same user.

23 23
Paired Arrays by Index
Click to edit Master title style

We will output the user’s credentials by using an


int variable as an index.

Sample Output:
Enter Index :0

Email : mark@gmail.com
Username : mark
Password : 1234
24 24
Click to edit Master title style

25 25
Click to edit Master title style

26 26
Click to edit Master title style

27 27
Click to edit Master title style

Arrays

28
Click to edit Master title style

Thank You. ❤

29
Sir Mark Leslie D. Melendez

You might also like