xxxxxxxxxx
Syntax:
return_type [][]varible_name=new return_type[no_of_rows][no_of_columns];
int [][]a=new int[5][5];
Valid Declearation are following:
int [][]a=new int[5][5];
int []a[]=new int[5][5];
int [][]a[]=new int[5][5][5];
xxxxxxxxxx
// Initializing an array during declaration
int[] numbers = {10, 20, 30, 40, 50};
xxxxxxxxxx
// Declaring and initializing an array of integers
int[] numbers = new int[5]; // Creates an array of size 5
// Assigning values to array elements
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;
numbers[3] = 40;
numbers[4] = 50;
// Accessing array elements
System.out.println(numbers[0]); // Output: 10
System.out.println(numbers[2]); // Output: 30
System.out.println(numbers[4]); // Output: 50