Top Posters
Since Sunday
L
3
d
3
y
3
a
3
n
3
d
3
e
3
d
3
c
3
p
3
M
3
a
3
New Topic  
Dymondmonae Dymondmonae
wrote...
Posts: 489
Rep: 9 0
4 years ago
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]);
}
}


▸ 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};

▸ The program compiles and runs fine and the output "Value is 1.0" is printed.

▸ 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};

▸ The program compiles and runs fine and the output "Value is 2.0" is printed.

▸ 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}.
Textbook 
Introduction to Java Programming, Comprehensive Version

Introduction to Java Programming, Comprehensive Version


Edition: 10th
Author:
Read 54 times
1 Reply
Replies
Answer verified by a subject expert
jfinn1021jfinn1021
wrote...
Posts: 388
4 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here
1

Related Topics

Dymondmonae Author
wrote...

4 years ago
Thanks
wrote...

Yesterday
Thanks for your help!!
wrote...

2 hours ago
Just got PERFECT on my quiz
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1026 People Browsing
Related Images
  
 1581
  
 367
  
 1037
Your Opinion