Question

In: Computer Science

Write a function called randFill that fills the entries of an array with random integers in...

Write a function called randFill that fills the entries of an array with random integers in the range from 10 to 99 (inclusive). (You should use a standard Java method to generate the values. Your solution should use no more than 6 lines of code.) For example, a program that uses the function randFill follows.

public class P4 {

public static void main(String args[]) {

int x[]; x = randFill(5);

for (int i = 0; i < 5; i++)

System.out.print(x[i] + " "); // prints 5 random numbers

System.out.println(); // such as 93 73 12 69 40

}

}

Solutions

Expert Solution

-------------------- I Used Online Java Compiler, Java Language, Console Application--------------------

--------------------Six Output Screenshots--------------------

--------------------CODE--------------------

import java.util.Random;
public class P4 {

static int[] randFill(int limit){
int[] numbers = new int[limit];
Random random = new Random();//Create instance of Random class called random
for (int i=0;i<limit;i++ )
numbers[i] = random.nextInt((99 - 10) + 1) + 10; //rand.nextInt((Max - Min) + 1) + Max;
return numbers; // return array of integers contains random numbers between 10 and 99(inclusive)
}

public static void main(String args[]) {
int x[]; x = randFill(5);
for (int i = 0; i < 5; i++)
System.out.print(x[i] + " "); // prints 5 random numbers
System.out.println(); // such as 93 73 12 69 40
}
}


Related Solutions

Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1...
Creates a 100-element array, either statically or dynamically Fills the array with random integers between 1 and 100 inclusive Then, creates two more 100-element arrays, one holding odd values and the other holding even values. Prints both of the new arrays to the console. In C++. Thank you!
1) Write a function searchValue that accepts an array of integers, the size of the array,...
1) Write a function searchValue that accepts an array of integers, the size of the array, and an integer. Find the last occurrence of the integer passed in as an input argument in the array. Return the index of the last occurrence of the value. If the value is not found, return a -1 2) Write the line of code to call the previous function assuming you have an array vec with length n, and are looking for the number...
write code to count the number of odd integers in an array of 100 random integers...
write code to count the number of odd integers in an array of 100 random integers in the range [0,99].
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers...
C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers called months and days to store the month and day of each date generated, a constant array of 12 integers called num_of_days that specify the number of days of each of the 12 months and an integer called size that specifies how many dates to generate and randomly generates size dates, storing the generated months in months array and generated days in days array....
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then...
*****IN JAVA***** Write a code snippet that initializes an array with ten random integers and then prints the following output: a. every element (on a single line) b. every element at an even index (on a single line) c. every even element (on a single line) d. all elements in reverse order (on a single line) e. only the first and last elements (on a single line)
Write a program in Java that initializes an array with ten random integers and then print...
Write a program in Java that initializes an array with ten random integers and then print three lines of output, containing: Every element at an odd index Every odd element All elements in reverse order   The program should use three different methods to implement the functionalities above. Call the primary source file ArrayManipulator.java
Write a code to initialize a 2D array with random integers (not has to be different)....
Write a code to initialize a 2D array with random integers (not has to be different). Write a function to count the number of cells that contain an even number within the 2D array. C++
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
Python Question: Write a function that checks to see if an array of integers is sorted...
Python Question: Write a function that checks to see if an array of integers is sorted in an increasing fashion, returning true if it is, false otherwise. Test it with at least4 arrays - 2 sorted and 2 not sorted. Use a CSV formatted input file as described in the previous question to run your program through some tests, where again the filename is passed as an argument. Heres what I have so far: import sys # command line arguement...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT