Arrays Unit 3
Arrays Unit 3
$ Alist of items can be given one variable name using only one subscript called single subscripted
variable or one dimensional array.
Eg: int number[]=new int[5):
For example, The values to the array elements 35, 40, 20, 57, 19 can beassigned as follows:
number[0] = 35;
number[1] =40;
number[2] = 20;
number[3] =57;
number[4] = 19;
CREATING AN ARRAY
$ Arrays must be declared and created in the computer memory before they are used.
Creation of an array involves three steps:
Declaring the array
Creating memory locations
Putting values into the memory locations.
Declaration of arrays
Initialization of Arrays
Putting values into the array is known as initialization.
number[ 1]-100;
< Arrays starts with a subscript Oand ends with avalue one les than the size specified.
Trying to access an array beyond its boundaries will generate an error message.
Initializing list of values to an array
Eg int numberl|-{23,45,56,67}
Array length
Access the length of the array using length keyword.
TWO DIMENSIONALARRAYS
Eg : int myarraylll:
myarray=new int|3||41;
Example program:
class MulTable
System.out.printin( «):
}