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.
1
Expert's answer
2012-11-28T09:55:44-0500
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 https://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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS