0

public class Program { public static void main(String[] args) { int[ ] intArr = new int[5]; int[5]={1,2,3};

this is the code .. but when i run it ...output comes with these error: ..\Playground\:5: error: ']' expected int[5]={'1','2','3'}; ^ ..\Playground\:5: error: not a statement int[5]={'1','2','3'}; ^ ..\Playground\:5: error: illegal start of expression int[5]={'1','2','3'}; ^ ..\Playground\:5: error: illegal start of expression int[5]={'1','2','3'}; ^ ..\Playground\:5: error: not a statement int[5]={'1','2','3'}; ^ ..\Playground\:5: error: ';' expected int[5]={'1','2','3'}; ^ ..\Playground\:6: error: <identifier> expected System.out.println(intArr.length); ^ ..\Playground\:6: error: <identifier> expected System.out.println(intArr.length); ^ ..\Playground\:8: error: class, interface, or enum expected } ^ 9 errors what it really means? if it gets total length of the array 5 ,why dont it accept the input with in the array size?

26th Jun 2017, 7:09 PM
gobiga rani
gobiga rani - avatar
2 Respuestas
+ 10
First of all, int[5] = {1,2,3} is missing the variable name. So it's a syntax error. Also, there's difference between array declaration and array initialization. If initialized with 3 values, then the compiler understands that the size is also 3. See the attached code: https://code.sololearn.com/cw1wFneU7fUC/?ref=app Edit: cute avatar 😊
26th Jun 2017, 7:25 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 1
needs to look somthing like this but depends what type of array your doing int [][] x = {{1,2,3},{4,5,6}};
26th Jun 2017, 7:20 PM
Uni Verse
Uni Verse - avatar