It is necessary to determine the maximum number of consecutive positive elements, not interrupted by either zeros or negative numbers. For example, in this case it is necessary to output the resulting array with the elements {6, 3, 5, 7, 7, 1} And how to make an outer loop so that it would iterate over all the sequence of numbers between the following negative numbers?
nt[] arr = { -1, 3, 4, 5, 9, -7, 6, 3, 5, 7, 7, 1, -9 }; int startIndex = 0; int endIndex = 0; for (int i = 0; i < arr.length; i++) { for (int k = 0; k < arr.length; k++) { if (arr[k] > 0) { startIndex = k; System.out.println(startIndex); break; } } for (int y = startIndex; y < arr.length; y++) { if (arr[y] < 0) { endIndex = y; System.out.println(endIndex); break; } } int length = endIndex - startIndex; System.out.println(length); }
arraycopyin general, if your array is now0 3 4 5 9 0 6 3 5 7 7 1 0andstartwill be equal to 1 ...... what can you understand from it? You have the wrong logic already - Alexey Shimansky