Quickly, we will recap about 1D array and do some iterations on it
Declaration
DataType nameOfArray [] = new DataType [lengthOfArray];
Example
int array [] = new int [5];
If I want to access an element in array
ArrayName[index]
array[2];
Note that arrays is zero based:
Array of length 5
The 1st element in array[0]
The last element array[lengthOfArray-1] = array[4]
Example
int array [] = new int [5];
array [0] = 7;
array [1] = 23;
array [2] = 20;
array [3] = 17;
array [4] = 45;
System.out.println( array[0] ); // will print 7
looping on 1D array
For (int i=0 ; i<array.length();i++)
{
System.out.println(array[i] ) ;
}
Great questions need some one to solve
1st and easy question
2nd question and easy too
last one but is medium !
Top comments (0)