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.
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.