Write the method body the method signature is provided for t

Write the method body (the method signature is provided) for the printSumEven method below. The method prints the sum of all of the even numbers in an array of integers. Your solution MUST use a while loop. For example, if this was the data in the array inputArr: 1, 6, 7, 2, 7, 3, 9, 3, 8, 5, 4 your code would print: Remember, your code must work for ANY values that might be in inputArr, not just the example given above. Enter your method body code below.

Solution

public void printSumEven(int[] inputArr)

{

int i=0;

int sum=0;

while(i<inputArr.length())

{

if(inputArr[i]%2==0)

sum=sum+inputArr[i];

i++;

}

System.out.println(\"sum of even numbers : \"+sum);

}

 Write the method body (the method signature is provided) for the printSumEven method below. The method prints the sum of all of the even numbers in an array of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site