Basic programming of array using Java
Java Programming Language Array in java (Article) Array in java (Program)
1238
This Java program demonstrates the creation and usage of an array. It initializes a double array myList with 4 values and uses a for loop to iterate over the array elements. During each loop iteration, the program prints the value at the current index.
The key components are:
- Array Declaration:
double[] myList = {3.9, 5.9, 22.4, 31.5}; - Loop: Iterates through the array using the index
i. - Output: Each array element is printed with
System.out.println().
Program:
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] + " "); } } }
Output:
3.9 5.9 22.4 31.5 Press any key to continue . . .
Explanation:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.