Create a new class MyArray_DE and copy and paste the previous program. Be sure to rename the class to MyArray_DE. Modify the program so that it sums up only the even numbers. PART E. At the end of the program, write a FOR loop that prints the array in reverse (you are not reversing the array; you are simply printing it). Test your program with all the above test cases.

Respuesta :

Answer:

public class MyArray_DE

{

public static void main(String[] args) {

    int[] numbers = {28, 7, 92, 0, 100, 77};

    int total = 0;

    for (int i=0; i<numbers.length; i++){

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

            total += numbers[i];

    }

 System.out.println("The sum of even numbers is " + total);

 System.out.println("The numbers in reverse is ");

 for (int i=numbers.length-1; i>=0; i--){

        System.out.print(numbers[i] + " ");

    }

}

}

Explanation:

Since you did not provide the previous code, so I initialized an array named numbers

Initialize the total as 0

Create a for loop that iterates through the numbers

Inside the loop, if the number % 2 is equal to 0 (That means it is an even number), add the number to total (cumulative sum)

When the loop is done, print the total

Create another for loop that iterates through the numbers array and print the numbers in reverse order. Note that to print the numbers in reverse order, start the i from the last index of the array and decrease it until it reaches 0.