import java.util.Scanner; import java.util.Random; public class BerkowitzLab7B { public static void main(String[] args) { // Call numberInput method and set it equal to an array integer int[] array = numberInput(); // Create instance of random class Random rand = new Random(); // Create and display variable that holds random number between 0 and 49 int randomNumber = rand.nextInt(49) + 1; System.out.println("Random number: " + randomNumber); // Call compareNumbers method to perform and display comparisons compareNumbers(randomNumber, array); } /** The numberInput method prompts the user to fill an array with numbers between 0 and 49. @return the filled array */ public static int[] numberInput() { // Create array int[] numbers = new int[10]; // Read user input Scanner keyboard = new Scanner(System.in); // For loop to fill array from user input for (int i = 0; i < numbers.length; i++) { System.out.println("Enter a number between 0 and 49: "); numbers[i] = keyboard.nextInt(); while (numbers[i] < 0 || numbers[i] > 49) { System.out.println("Invalid input. Try again."); System.out.println("Enter a number between 0 and 49: "); numbers[i] = keyboard.nextInt(); } System.out.println("You entered " + numbers[i] + ".\n"); } return numbers; } /** The compareNumbers method compares and displays the array to the random number @param randomNumber Represents the value of the random number @param array Represents the value of the array */ public static void compareNumbers(int randomNumber, int[] array) { // For loop to compare random number to array element for (int i = 0; i < array.length; i++) { if (array[i] > randomNumber) { System.out.println(array[i] + " is greater than " + randomNumber + "."); } else if (array[i] < randomNumber) { System.out.println(array[i] + " is less than " + randomNumber + "."); } else if (array[i] == randomNumber) { System.out.println(array[i] + " is equal to " + randomNumber + "."); } } } }