Long array use for input and output

what is the problem in this code
import java.util.*;

public class Main

{
public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);
	long n = sc.nextLong();
	long arr[] = new long[n];

	for(long i=0;i<n;i++)

	arr[i]=sc.nextLong();

	for(long i=0;i<n;i++)
	System.out.println(arr[i]);

}

}

@neelesh_garg 1

The size of an array can only be an int. So maximum array size is (aproximately) Integer.MAX_VALUE. For bigger arrays you should use ArrayList.

to get around this you can do
long arr = new long[(int)(n)];

1 Like

Please mark your doubt as resolved if you are satisfied and you can give ratings too based on my response :slight_smile: