What would be the result of attempting to compile and run the following code?
```
public class Test {
public static void main(String[] args) {
double[] x = new double[]{1, 2, 3};
System.out.println("Value is " + x[1]);
}
}
```
a. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.
b. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};
c. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};
d. The program compiles and runs fine and the output "Value is 1.0" is printed.
e. The program compiles and runs fine and the output "Value is 2.0" is printed.
e. The program compiles and runs fine and the output "Value is 2.0" is printed.
new double[]{1, 2, 3} is correct. This is the syntax I have not covered in this edition, but will be covered in the future edition. In this question, double[] x = new double[]{1, 2, 3} is equivalent to double[] x = {1, 2, 3};
You might also like to view...
When a link leads to another page, the page where the link is included is called the ____ page.
A. target B. linking C. referring D. source
____ properties allow you to supply a drop-down list of values for a field.
A. Key B. Relationship C. Lookup D. Junction
The two optional arguments in the PMT function allows the function to be used with variable loans.
Answer the following statement true (T) or false (F)
The ____ command-line utility is used to trace the route a packet of information takes to get to its target.
A. ping B. ping -a 192.168.1.1 C. tracert D. tracepath