Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following methods to work on an array of integers. The main method wil

ID: 3669658 • Letter: W

Question

Write the following methods to work on an array of integers. The main method will read 10 numbers from the user and store them in an array. Main will call the other methods using the array, then display the results.

void printArray(int list[])
Input: an array of integers
Output: the method does not return any output. Instead, the method prints on
the screen all values on the array


int range(int list[ ])
Input: an array of integers.
Output: difference between the maximum and minimum values in the array.


int[] reverseArray(int list1[])
Input: an array of integers.
Output: an array with the same size as the input array. The output array contains
the same integers as the input array but in reverse order. For example, if the
input array contains [5,6,7,4,3] then the output array will contain [3,4,7,6,5].


int numEven(int list[])
Input: an array of integers .
Output: The number of even values in the array. If the input array
contains 3,3,5,6,5,1,1,2, the method returns 2 because there are only two
even values in the array (6 and 2).


int sumEven(int list[])
Input: an array of integers.
Output: The sum of all even values in the array.If the input array
contains[ 3,3,5,6,5,1,1,2]. Then, the method returns 8 because there are two
even values, 6 and 2, then the sum is 8.

Explanation / Answer

import java.io.*;

import java.util.*;

public class Integer {

public static void main(String args[]) throws Exception {

int i,num=1;

ArrayList arr[] = new ArrayList();

for(i=0;i<10;i++) {

arr[i]=num;

}

void print Array(int arr[]);

int range(int arr[]);

int[] reverseArray(int arr[]);

int numEven(int arr[]);

int sumEven(int arr[]);

}

void print Array(int arr[]) {

System.out.println(“ The array of numbers “ + arr[]);

}

int[] reverseArray(int arr[]) {

int temp,start,end;

if ( start >= end)

return;

temp=arr[start];

arr[start]=arr[end];

arr[end]=temp;

start +1;

end-1;

int[] reverseArray(int arr[]);

}

int range(int arr[]) {

int max=0,min=0,range=0;

for(int i=0;i<10;i++) {

if(i>max) {

max=i;

} else if (i<min) {

min=i;

}

range = max – min +1;

return range;

} }

int numEven(int arr[]) {

int i,num;

for(i=0;i<10;i++) {

if(num %2==0)

system.out.println(“even” + num);

else return false;

} }

int sumEven(int arr[]) {

int sum,i;

for (i=0;i<10;i++) {

if(arr[i]%2==0){

sum=arr[i] +sumEven(arr[]);

} else

sum = sumEven(arr[]);

}

System.out.println(“The sum of even number is “+ sum);

}

}