Home / Programs / Traversing an Array in java
🚀 Programming Example

Traversing an Array in java

👁 33 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 Program Code

public class TraverseArray {
    public static void main(String[] args) {
        int[] arr = {5, 10, 15, 20, 25};

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

        System.out.println("\nUsing enhanced for loop:");
        for(int num : arr){
            System.out.print(num + " ");
        }
    }
}

                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.