How to find size/length of an array without using library functions/variables [closed]

int arr[] = new int[100];

int sum = 0;
int i = 0;
while (true) {
  try {
    sum += arr[i];
  } catch (ArrayIndexOutOfBoundsException e) {
    break;
  }
  i++;
}

System.out.println("Array is of size " + i);

I’m assuming array is of ints, but the idea is the same.

Browse More Popular Posts

Leave a Comment