Day 28

 

How to Work with One Dimensional Arrays

1. Accessing Elements:

You can access any element in the array using its index:

System.out.println(arr[2]); // Output: 30

2. Modifying Elements:

You can update the value of any element:

arr[3] = 100; System.out.println(arr[3]); // Output: 100

3. Iterating Over the Array:

You can use loops, such as for or for-each, to iterate through the array:

for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }

Practical Examples of One Dimensional Arrays

Example 1: Finding the Sum of Array Elements










Example 2: Searching for an Element in the Array       
 

 
                                                                                    Example 3: Reversing the Array

تعليقات

المشاركات الشائعة