Fill an array with ten random integers between 1 and 30 (inclusive, meaning you
ID: 3733988 • Letter: F
Question
Fill an array with ten random integers between 1 and 30 (inclusive, meaning you should be able to have 1 and 30). Write the method printArray which outputs the numbers so you can see what they were. Also write the methods findLargest and findSmallest.
import java.util.Random;
public class L12Num1 {
public static void main(String[] args) {
int[] myArray = new int[10];
Random randGen = new Random(); // New random number generator
//fill the array
//output the array
System.out.println("The contents of the array are: ");
printArray(myArray);
int largest = findLargest(myArray);
int smallest = findSmallest(myArray);
System.out.println("The largest element in the array is " + largest);
System.out.println("The smallest element in the array is " + smallest);
}
public static void printArray(int[]A)
{
}
public static int findLargest(int[] A)
{
}
public static int findSmallest(int[] A)
{
}
}
Explanation / Answer
import java.util.Random; public class L12Num1 { public static void main(String[] args) { int[] myArray = new int[10]; //Random randGen = new Random(); // New random number generator int min = 10, max = 100; int range = (max - min) + 1; //fill the array for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.