Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA HELP Show two ways to declare a one-dimensional array of 12 doubles. {1.0,

ID: 3687485 • Letter: J

Question

JAVA HELP

Show two ways to declare a one-dimensional array of 12 doubles.

{1.0, 2.0, 3.0, 4.0, 5.0, 6.0,7.0, 8.0, 9.0, 10.0, 11.0, 12.0};

For the first example print the 7.0 and 10.0 in a println.

Example - Your println should match

7.0

10.0

For the first example print the 2.0 and 12.0 in a println.

Example - Your println should match

2.0

12.0

Show two ways to declare a one-dimensional array of 12 doubles.

{1.0, 2.0, 3.0, 4.0, 5.0, 6.0,7.0, 8.0, 9.0, 10.0, 11.0, 12.0};

For the first example print the 7.0 and 10.0 in a println.

Example - Your println should match

7.0

10.0

For the first example print the 2.0 and 12.0 in a println.

Example - Your println should match

2.0

12.0

Explanation / Answer

First way to declare a one dimensional array is

double values[] = new double[12];

Second way to declare and initialize a one dimensional array with doubles.

double values[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0,7.0, 8.0, 9.0, 10.0, 11.0, 12.0};  

Test27.java


public class Test27 {
   public static void main(String arg[]){
       double values[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0,7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
       System.out.println(values[6]);
       System.out.println(values[9]);
       System.out.println("----------------------");
       System.out.println(values[1]);
       System.out.println(values[11]);
   }
}

Output:

7.0
10.0
----------------------
2.0
12.0