-2
class lab1{

    public static void main(String[] args){

        int arr[]= new int[2147483647];
        System.out.println(arr.length);
    }
}
Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

1

The problem is, as the error states, that the array is too big:

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
    at lab1.main(lab1.java:7)

This is because there is a set maximum size of arrays in Java.

For more information, you should see: Do Java arrays have a maximum size?

Community
  • 1
  • 1
Tom Leese
  • 19,309
  • 12
  • 45
  • 70