Computer Science, asked by Reva06, 8 months ago

Consider this C Program, C++ Program, Java Program or C# Program. It reads integers from the standard input (until it gets a negative number) and puts them into an array. After that it calls processArray on the array, and then prints the value that is returned to standard output. Currently, processArray does not do anything useful - it just returns 0. You have to change this program so that it counts the number of sequences of consecutive even numbers in the array where the sum of the numbers in the sequence is greater than or equal to 20, and returns that number. Note: for the purposes of this question, a single even number is considered a sequence of length 1 if it does not have any other even numbers next to it. For example, if these numbers were provided on the standard input: 3 6 6 4 121 6 16 371 661 6 -1 Then the program should print: 1 This is because there are three sequences of consecutive even numbers here, but only one of them has a sum that's greater than or equal to 20 (6 + 16 = 22).

Answers

Answered by kaustubhdubey
8

Answer:

class Main {

   public static void main(String[] args) {

       //System.out.println("Hello, World!");

       int arr[] = {3,9,36,62,121,64,21,3,660,6,-1};

      int cnt = 0;

       for(int i=0;i<arr.length-1;i++){

           if(arr[i]%2!=0&&arr[i+1]%2!=0 && arr[i]+arr[i+1]>=20){

               cnt++;

           }

       }

       System.out.println(cnt);

   }

}

Explanation:

Program in Java

Similar questions