Home Java Programming Language / Programs / how to create, initialize, and process arrays
🚀 Programming Example

how to create, initialize, and process arrays

👁 1,366 Views
💻 Practical Program
📘 Step Learning
how to create, initialize, and process arrays

💻 Program Code

public class ArrayExample {

    public static void main(String[] args) {
         double[] myList = {3.9, 5.9, 22.4, 31.5};

         // Print all the array elements
         for (int i = 0; i < myList.length; i++) {
            System.out.println(myList[i] + " ");
         }

         // Summing all elements
         double total = 0;
         for (int i = 0; i < myList.length; i++) {
            total += myList[i];
         }
         System.out.println("Total is " + total);

         // Finding the largest element
         double max = myList[0];
         for (int i = 1; i < myList.length; i++) {
            if (myList[i] > max) max = myList[i];
         }
         System.out.println("Max is " + max);
   }
}
                        

🖥 Program Output

3.9
5.9
22.4
31.5
Total is 63.7
Max is 31.5
Press any key to continue . . .
                            

📘 Explanation

None
📚 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.