Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Using a for loop to iterate over all the elements and set the values

public class MainClass {   public static void main(String[] arg) {     double[] data = new double[50]; // An array of 50 values of type double     for (int i = 0; i < data.length; i++) { // i from 0 to data.length-1       data[i] = 1.0;     }          for (int i = 0; i < data.length; i++) { // i from 0 to data.length-1       System.out.println(data[i]);     }        } } 1.0 1.0