I need to pass a predefined array into a new method to populate the array with 10 random ints
int[] intList = new int[10];
//Need Help creating method to pass the above array into a method that assigns random ints to each of the 10 slots in the array.
So, here is the complete code in Java.
import java.util.Random;
public class Main {
// function to populate array with random numbers
public int[] populate_array(int[] arr){
Random rd = new Random(); // creating Random object
int limit = 50; //To generate random no between 0,50
for (int i = 0; i < arr.length; i++) {
arr[i] = rd.nextInt(limit); // storing random integers in an
array
}
return arr; // return the int array with random int
}
public static void main(String[] args) {
Main obj = new Main();
int[] intList = new int[10];
// call the function to pupulate inList array with random
numbers
intList = obj.populate_array(intList);
// print the array elements
for (int i = 0; i < intList.length; i++) {
System.out.print(intList[i] + ", "); // printing each array
element
}
}
}
The program output is :
37, 41, 49, 32, 16, 7, 10, 9, 45, 43,
I need to pass a predefined array into a new method to populate the array with...
Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...
[JAVA] I need help creating a method to calculate the Standard Deviation of a 2D Array. This is what I have so far: public double calcStdDev() { int total = 0; for(int i = 0; i < arr.length; i++){ total += arr[i][i]; } double mean = total / arr.length; return mean; } The numbers I'm using at just 1,2,3,4,5,6 and the standard deviation is coming out wrong. Can I have help fixing my...
-I need help with C++. I'm working with an array of words. The array size is 1000 but not all 1000 slots will be filled. I run an insertion sort algorithm and then output the array but the sorted array output includes the unused empty slots so there is a lot of blank spaces before the sorted words appear. -The sorting algorithm seems to be reading in the empty array slots as well. Is there a way to read an...
I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...
Please I need code in C++ Write a program that creates an int array of size 10, then uses a for-loop to populate the array with numbers from your favorite number pattern.
Hello, I need a c program called int* create_random_array(int n) that returns a random array of size an. Alternatively, you can initialize a pointer to an array (called Rand) and write a function called void(create_array(int * Rand, int n) which assigns an array of size n to Rand. Note: Plese utilize rand(fi) and srand() from stdlib.h for this code
HOW TO FiX EXCEPTIONS??? In order to populate the array, you will need to split() each String on the (,) character so you can access each individual value of data. Based on the first value (e.g., #) your method will know whether to create a new Manager, HourlyWorker, or CommissionWorker object. Once created, populate the object with the remaining values then store it in the array. Finally, iterate through the array of employees using the enhanced for loop syntax, and...
So this is all I have done
right now. Next steps:
1. Create a method called "printArray" which would put the code
: for(int i = 0; i < myArray.length; i++)
System.out.println(myArray[i]); at the bottom of that screen and
put it into a method and then call it.
2. Create another method thats going to count all the numbers
that are evenly divisible by 10 and call the method whatever you
like.
* Just make sure to return, pass at...
Below I have done a bubble sort on an array. I need to figure out how to change the --- bubbleSort() method... with a new method called oddEvenSort() method.. I know I have to do two passes one for odd, one for even, can I have someone help me do this please I keep getting a lot of errors when I attempt to do it. Java code to change is below. I have to sort the array using one pass...
I ONLY NEED PART 4 I HAVE DONE 1,2,3 Arrays This assignment is designed in small progressive parts, with the intention of developing the skill of working with arrays. Do each part separately. Include in your submission the code and output for Part I, then the code and output for Part 2, etc. into a Word document. Specification: Part 1. Write a main function that declares an array of 10 int’s. Assign each element in the array a value between...