Ask Question
15 March, 18:35

write a program that takes 10 numbers as input and displays the mode of the numbers using parallel arrays and a method that takes an array of numbers as a parameter and returns the value that appears most often in the array

+1
Answers (1)
  1. 15 March, 18:55
    0
    The Java program is explained below

    Explanation:

    public class ArrayMode {

    public static int mode (int arr[]) {

    int maxValue = 0, maxCount = 0;

    for (int i = 0; i < arr. length; + +i) {

    int count = 0;

    for (int j = 0; j < arr. length; + +j) {

    if (arr[j] = = arr[i])

    ++count;

    }

    if (count > maxCount) {

    maxCount = count;

    maxValue = arr[i];

    }

    }

    return maxValue;

    }

    public static void main (String args[]) {

    int arr[] = { 9, 5, 3, 8, 5, 12, 19, 5, 11 };

    System. out. println ("The set of numbers are: ");

    for (int i = 0; i < arr. length; i++)

    System. out. print (arr[i] + " ");

    System. out. println ("/nThe mode of the set is: " + mode (arr));

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “write a program that takes 10 numbers as input and displays the mode of the numbers using parallel arrays and a method that takes an array ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers