Download presentation
Presentation is loading. Please wait.
Published byCrystal Dickerson Modified over 8 years ago
1
Array (2) Lecture Week 9
2
Moga Memperoleh Keberkatan Ramadhan Berterusan Array Review Array is a structure to store values of the same type The values can be reuse, manipulate and change Use to store similar entity with different values
3
Moga Memperoleh Keberkatan Ramadhan Berterusan What is the output? int size = 5; int [ ] num = { 2,4,6,8,10}; for (int i=0; i < size; i++) num [i] *= 3; System.out.println(“New list”); for (int i=0; i < size; i++) System.out.print (num[i] + “ “); System.out.println();
4
Moga Memperoleh Keberkatan Ramadhan Berterusan Array Revisited Using Array With Methods Using Array as Objects Searching an Array 2D Array Multidimensional Array
5
Moga Memperoleh Keberkatan Ramadhan Berterusan Using Array With Methods Sending an element of an array Example 2 Sending an array Example 3 Returning an array Example 4
6
Using Array of Objects Moga Memperoleh Keberkatan Ramadhan Berterusan Example 5
7
Searching an Array Useful in looking for element in an array Example 6 Moga Memperoleh Keberkatan Ramadhan Berterusan
8
2D Array Java support 2 dimensional array – similar structure with matrix or table E.g int [] [] matrix = new int [3] [3]; By default numerical array will store value 0; eg. matrix[0][0] = 1; matrix[1][1] = 1; matrix[2][2] = 1; Moga Memperoleh Keberkatan Ramadhan Berterusan | 1 0 0 | | 0 1 0 | | 0 0 1 | for (int i=0; I < matrix.length; i++) for (int j=0; j <matrix[i].length; j++) if (i == j) matrix[i][j] =1;
9
Multidimensional Array Can have more than 2 dimension. residential college has many levels At each level has many rooms. E.g accomodation [1][3][12] could be referring accomodation at college[1] at level 3 room no. 12. Moga Memperoleh Keberkatan Ramadhan Berterusan
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.