Professional Documents
Culture Documents
Arrays: Sensitivity: Internal & Restricted
Arrays: Sensitivity: Internal & Restricted
Array elements are automatically initialized with the default value of their type, when
created.
Ex:
Ex:
int[] x = new int[10];
int x_len = x.length;
The 1st dimension represent rows and the 2nd dimension represent columns.
The curly braces { } may also be used to initialize two dimensional arrays.
Ex:
int[][] y = { {1,2,3}, {4,5,6}, {7,8,9} };
1. int[] a;
a = new int[5];
2. int a[] = new int[5]
3. int a[5] = new int[5];
4. int a[] = {1,2,3};
5. int[] a = new int[]{1,2,3};
6. int[] a = new int[5]{1,2,3,4};
class Sample {
public static void main(String[] args) {
int[] a = new int[5]{1,2,3};
for(int i : a)
System.out.println(i);
}
}
class Test {
public static void main(String [] args) {
int [] x=new int[10];
System.out.println(x[4]);
}
}
class Test {
public static void main(String [ ] args) {
int x[ ][ ]=new int[10] [ ];
System.out.println(x[4][0]);
}
}
Understand how to work with single and two dimensional arrays in Java