info@meritcampus.com    +91-85006-22255
...

Write a program to sum of consecutive 3 numbers in the input array.
NOTE: The input array size may NOT be a perfect multiple of 3.

Input (Integer Array) Output (Integer Array)
`{2, 3, 4, 7, 6, 1}` `{(2 + 3 + 4), (7 + 6 + 1)} = {9, 14}`
`{3, 9, 1, 5, 16, 10, 4}` `{(3 + 9 + 1), (5 + 16 + 10), (4)} = {13, 31, 4}`
`{3, 9, 1, 5, 16, 10, 4, -6}` `{(3 + 9 + 1), (5 + 16 + 10), (4 + -6)} = {13, 31, -2}`

``` class SumOfThreeConsecutiveNumbersInArray {    public static void main(String s[])    {        int[] input = {2, 6, 3, 8, 1};        int[] output = sumOfThreeConsecutiveNumbers(input);        System.out.print("Output array is : ");        for(int i = 0; i < output.length; i++)        {            System.out.print(output[i] + ", ");        }    } public static int[] sumOfThreeConsecutiveNumbers(int[] input) { int[] output = null; //Write code here to sum of consecutive 3 numbers in input array and assign it to output return output; } } ```

Topic: Learn Arrays And Loops

0
Wrong
Score more than 2 points