63 041
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #19689 in AJAX | JavaScript | HTML | PHP for nohra

Question #19689
You coded the following on line 26 of the class Test.java: int a[6] = {2, 7, 8, 9, 11, 16 }; // line 26
When you compile, you get the following messages:
Test.java:26: ']' expected
int a[6] = { 2, 7, 8, 9, 11, 16 }; // line 26
^
Test.java:26: not a statement
int a[6] = { 2, 7, 8, 9, 11, 16 }; // line 26
^
Test.java:26: ';' expected
int a[6] = { 2, 7, 8, 9, 11, 16 }; // line 26
3 errors
Explain what the problem is and how to fix it.
Expert's answer
One way to create an array is with the new operator. Thenext statement in the ArrayDemo program allocates an array with enough memory
for ten integer elements and assigns the array to the anArray variable.
// create an array of integers
anArray = new int[10];

Alternatively, you can use the shortcut syntax to createand initialize an array:
int[] anArray = {
100, 200, 300,
400, 500, 600,
700, 800, 900,1000
};

more information http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

So, correct initialization: int a[] = { 2, 7, 8, 9, 11, 16 }; or int[] a= { 2, 7, 8, 9, 11, 16 };

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions