class ArrayDeclarationInit{
public static void main(String[] args) {
// Declaring an array of integers
int[] numbers;
// Initializing the array with values
numbers = new int[]{1, 2, 3, 4, 5};
}
}
class ArrayAccessingExample{
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
// Accessing the first element
int firstNumber = numbers[0];
System.out.println("firstNumber"+ firstNumber);// firstNumber: 1
// Accessing the third element
int thirdNumber = numbers[2];
System.out.println("thirdNumber"+ thirdNumber);// thirdNumber: 3
}
}
class Arraylength{
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
// Getting the length of the array
int length = numbers.length;
System.out.println("length"+"="+ length); // length = 5
}
}
class MultiArrayFor{
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
// Printing all elements using the enhanced for loop
for (int number : numbers) {
System.out.println(number);
}
}
}
Arrays can have multiple dimensions, allowing you to create tables or matrices.