+ 1

Pls tell me why the code below is not working

public class Program { public static void main(String[] args) { int Arr[5]; System.out.println(Arr.length); } }

19th Jul 2017, 3:46 PM
Rajeet Goyal
Rajeet Goyal - avatar
3 Respuestas
+ 16
That's not the way to declare an array in Java. That's the c++ way I guess. This would help : int arr[] = new int[5];
19th Jul 2017, 3:52 PM
Dev
Dev - avatar
+ 3
array declaration is wrong int arr []=new int [5]
19th Jul 2017, 3:52 PM
Nirmal Kumar Bhakat
Nirmal Kumar Bhakat - avatar
+ 2
you need to define the array's capacity, or the number of elements it will hold.
20th Jul 2017, 3:40 PM
Hoshea Wang
Hoshea Wang - avatar