A one-dimensional array is a linear data structure that stores elements of the same data type in a single sequence or row. Each element is accessed using its index, starting from zero. It is commonly used to represent a list or series of values.
The OneDimensionalArray Java program demonstrates the creation and manipulation of a one-dimensional array of characters.
It declares an array named letters
with a size of 5 and assigns values ('a', 's', 'd', 'f', 'g') to its elements. The program then utilizes a for loop to iterate through the array, printing each character to the console.
A two-dimensional array is a grid-like data structure with rows and columns, where elements are accessed using two indices, one for the row and another for the column. It is suitable for representing tables or matrices, allowing for the organization of data in a structured and efficient manner.
The TwoDimensionalArray Java program demonstrates the creation and manipulation of a two-dimensional array of strings.
It declares a 2D array named table
with dimensions 11x5 and assigns the string "hello" to each element. The nested for loops traverse the array, printing the string values to the console in a tabular format.