Untitled
unknown
java
2 years ago
619 B
4
Indexable
public class HelloWorld { public static void main(String[] args) { // Define an integer array int[] arr = {3, 9, 36, 62, 121, 64, 21, 3, 660, 6, -1}; int cnt = 0; // Correct the loop variable from I to i for (int i = 0; i < arr.length - 1; i++) { // Check if both current and next elements are odd and their sum is greater than or equal to 20 if (arr[i] % 2 != 0 && arr[i + 1] % 2 != 0 && arr[i] + arr[i + 1] >= 20) { cnt++; } } System.out.println(cnt); } }
Editor is loading...