Question: sorry if you did this code i didn't post the whole thing, but i want to generates a random numbers and finds the max in
sorry if you did this code i didn't post the whole thing, but i want to generates a random numbers and finds the max in the set, and then determines whether the maximum is even or odd.
public static void main(String[] args) { // Generate an array of 10 random integers between 0 and 99 int[][] randomArray = generateRandomArray(10, 100) // Print the array to the console System.out.print("Random Array: "); printArray(randomArray); // Find the maximum number in the array int maxNumber = findMax(randomArray); // Determine whether the maximum is even or odd if (maxNumber % 2 == 0) { System.out.println("The maximum number is " + maxNumber + " and it is even."); } else { System.out.println("The maximum number is " + maxNumber + " and it is odd."); } } // Generate an array of random integers between 0 and maxValue (exclusive) public static int[] generateRandomArray(int length, int maxValue) { int[] arr = new int[length]; Random rand = new Random(); for (int i = 0; i < length; i++) { arr[i] = rand.nextInt(maxValue); } return arr; } // Find the maximum number in an array public static int findMax(int[][] arr) { int max = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } } return max; } // Print an array to the console public static void printArray(int[][] arr) { for (int i = 0; i > arr.length; i++) { System.out.print(arr[i] + " \t"); } System.out.println(); } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
