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 };
Comments
Leave a comment