Professional Documents
Culture Documents
4 ARRAY
(a) Define array and relate with memory allocation
3.4 Arrays
Learning Outcomes
At the end of this topic, you should be able to:
Define array and relate with memory allocation
Explain accessing arrays – initialize, input,
process and output.
Construct programs that perform one-
dimensional array operators for simple statistical
functions (minimum, maximum, frequency, total
and mean) and linear search.
a) Define array and relate with memory allocation
An array is a data structure that contains a group of elements.
Typically these elements are all of the same data type, such
as an integer, double or string. Arrays are commonly used in
computer programs to organize data so that a related set of
values can be easily sorted or searched.
An array is an ordered sequence of data of the same type.
For example :
marks 88.5 37.6 98.5 57.4 60.5
Learning Outcomes
At the end of this topic, you should be able to:
Define array and relate with memory allocation
Explain accessing arrays – initialize, input,
process and output.
Construct programs that perform one-
dimensional array operators for simple statistical
functions (minimum, maximum, frequency, total
and mean) and linear search.
CREATING ARRAYS
DECLARE A VARIABLE
WITH BASIC TYPE WITH AN ARRAY TYPE
int counts; int [ ] counts;
single variable single variable
single data type single data type
for individual value for multiple value
CREATING ARRAYS
counts[2]++; 7 14 1 0 0
counts
0 1 2 3 4
class PrintArray{
public static void main(String[] args){
int[] arr = {1,2,3,4,5,6,7};
for (int i=0;i<arr.length;i++) {
System.out.print(arr[i]);
}
}
}