Skip to content
Snippets Groups Projects

Master

Merged 663040 665-6 requested to merge master into main
1 file
+ 30
0
Compare changes
  • Side-by-side
  • Inline
ArrayExample.java 0 → 100644
+ 30
0
public class ArrayExample {
public static void main(String[] args) {
// Declare and initialize an array of integers
int[] numbers = new int[5];
// Assign values to the array elements
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;
numbers[3] = 40;
numbers[4] = 50;
// Print the values of the array elements
System.out.println("Array elements:");
for (int i = 0; i < numbers.length; i++) {
System.out.println("Element at index " + i + ": " + numbers[i]);
}
// Alternative way to initialize and declare an array
String[] names = {"Alice", "Bob", "Charlie", "Diana"};
// Print the values of the string array elements
System.out.println("\nString array elements:");
for (int i = 0; i < names.length; i++) {
System.out.println("Element at index " + i + ": " + names[i]);
}
}
}
\ No newline at end of file
Loading