60 734
Assignments Done
97,9%
Successfully Done
In April 2018

Answer to Question #58048 in Java | JSP | JSF for Abdi

Question #58048
Method 1: createArray

Write a method that creates an integer array of size 100. Once created, use some type of loop to fill the array with random integers. Make sure these integers are in the range [0-99]. This method should accept no parameters and return an integer array. Therefore, the method header should look as follows:

public static int[] createArray()





Method 2: statsDisplay

Write a method that performs some rudimentary statistics on the recently created array. The statistics to take are as follows:

Count and display the amount of even numbers (Note: You do not have to print the actual numbers).

Count and display the amount of odd numbers (Note: You do not have to print the actual numbers).

Calculate and display the average.


Expert's answer
public static int[] createArray() {

int size = 100;
int[] array = new int[size];

for (int i = 0; i < array.length; i++) {
array[i] = (int) (Math.random() * 100);
}

return array;
}

public static void statsDisplay(int[] array) {

int amountEvenNumbers = 0;
int amountOddNumbers = 0;
int summ = 0;
double average = 0;

for (int i = 0; i < array.length; i++) {
if (array[i] % 2 == 0) {
amountEvenNumbers++;
} else {
amountOddNumbers++;
}
summ += array[i];
}

average = (1. * summ) / array.length;
System.out.println("Amount of even numbers : " + amountEvenNumbers);
System.out.println("Amount of odd numbers : " + amountOddNumbers);
System.out.println("Average : " + average);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions