a. I input an array of integers: int[] arr = { 4, 100, 2, 50, 7, -45, -23, 84, 51, 120, 98, -72 }. b. Declare an integer variable that named "total". c. create a loop. d.1. The loop control variable value to be declared is 0. This will be represented by the variable "i" and it represents the index of the inputted array. e.2. The loop has a condition that if the current loop control variable value is greater than or equal to the size of the array minus the first item of the array, the loop will break. f.3. After the body or function is executed, the loop control variable is incremented by 2. g.4. The body of the loop has a conditional statement. if arr[i] is even, add it to total, else minus it to the total. g. After the loop breaks or finishes, display the value of the total
Program this in java:
a. I input an array of integers: int[] arr = { 4, 100, 2, 50, 7, -45, -23, 84, 51, 120, 98, -72 }.
b. Declare an integer variable that named "total".
c. create a loop.
d.1. The loop control variable value to be declared is 0. This will be represented by the variable "i" and it represents the index of the inputted array.
e.2. The loop has a condition that if the current loop control variable value is greater than or equal to the size of the array minus the first item of the array, the loop will break.
f.3. After the body or function is executed, the loop control variable is incremented by 2.
g.4. The body of the loop has a conditional statement. if arr[i] is even, add it to total, else minus it to the total.
g. After the loop breaks or finishes, display the value of the total.
Step by step
Solved in 3 steps with 1 images