It is used to store double data type values only. With the following examples you can learn how to declare double array, how to assign values to double array and how to get values from double array.
/* double Array Example */ /* Save with file name DoubleArray.java */ public class DoubleArray { public static void main(String args[]) { //DOUBLE ARRAY DECLARATION double a[]; //MEMORY ALLOCATION FOR DOUBLE ARRAY a = new double[4]; //ASSIGNING ELEMENTS TO DOUBLE ARRAY a[0] = 100000d; a[1] = 300000d; a[2] = 400000d; a[3] = 786777d; //DOUBLE ARRAY OUTPUT System.out.println(); System.out.println("double Array Example"); System.out.println("=================="); System.out.println(); for(int i=0;i<a.length;i++) { System.out.println("Element at Index : "+ i + " " + a[i]); } } }
In this example you can learn how to assign values to double array at the time of declaration.
/* double Array Example 2 */ /* Save with file name DoubleArray2.java */ public class DoubleArray2 { public static void main(String args[]) { //DOUBLE ARRAY DECLARATION double a[] = {100000d,300000d,400000d,786777d}; //DOUBLE ARRAY OUTPUT System.out.println(); System.out.println("double Array Example"); System.out.println("=================="); System.out.println(); for(int i=0;i<a.length;i++) { System.out.println("Element at Index : "+ i + " " + a[i]); } } }
In this example you can learn how to declare double array with other double variables.
/* double Array Example 3 */ /* Save with file name DoubleArray3.java */ public class DoubleArray3 { public static void main(String args[]) { //DOUBLE ARRAY DECLARATION double a[], a2; //MEMORY ALLOCATION FOR DOUBLE ARRAY a = new double[4]; //ASSIGNING ELEMENTS TO DOUBLE ARRAY a[0] = 100000d; a[1] = 300000d; a[2] = 400000d; a[3] = 786777d; a2 = 333333d; //DOUBLE ARRAY OUTPUT System.out.println(); System.out.println("double Array Example"); System.out.println("=================="); System.out.println(); System.out.println("a2 value is : "+a2); System.out.println(); for(int i=0;i<a.length;i++) { System.out.println("Element at Index : "+ i + " " + a[i]); } } }
In this example you can learn how to assign double array to other double array.
/* double Array Example 4 */ /* Save with file name DoubleArray4.java */ public class DoubleArray4 { public static void main(String args[]) { //DOUBLE ARRAY DECLARATION double[] a, a2; //a AND a2 ARE ARRAY VARIABLES //MEMORY ALLOCATION FOR DOUBLE ARRAY a = new double[4]; //ASSIGNING ELEMENTS TO DOUBLE ARRAY a[0] = 100000d; a[1] = 300000d; a[2] = 400000d; a[3] = 786777d; //ASSIGNING a ARRAY TO a2 ARRAY VARIABLE a2 = a; //DOUBLE ARRAY OUTPUT System.out.println(); System.out.println("double Array Example"); System.out.println("=================="); System.out.println(); System.out.println("a array values"); System.out.println(); for(int i=0;i<a.length;i++) { System.out.println("Element at Index : "+ i + " " + a[i]); } System.out.println(); System.out.println("a2 array values"); for(int i=0;i<a2.length;i++) { System.out.println("Element at Index : "+ i + " " + a2[i]); } } }