Ask Question
22 February, 01:23

java Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an integer indicating the number of words that follow. Assume that the list will always contain less than 20 words.

+4
Answers (1)
  1. 22 February, 03:49
    0
    The following are the program in the Java Programming Language.

    //set a package

    import java. util. Scanner;

    //define class

    public class Main

    {

    //define a main method

    public static void main (String[] args)

    {

    //declare the Scanner class object

    Scanner s = new Scanner (System. in);

    //get the size of the array from the user

    int size=s. nextInt ();

    //declare an integer array with given size

    int a[]=new int[size];

    //declare a string array with given size

    String word[]=new String[size];

    //set the for loop

    for (int i=0; i
    //get string input from the user

    word[i]=s. next ();

    //iterates with the array, increase the count

    for (int i=0; i
    {

    for (int j=0; j
    {

    //check that elements of words

    if (word[i]. equals (word[j]))

    //increament in the array by 1

    a[i]++;

    }

    }

    System. out. print ("/n");

    //set for loop to print the following result

    for (int i=0; i
    System. out. println (word[i]+" "+a[i]);

    }

    }

    Explanation:

    The following are the description of the program.

    Firstly, set the required predefined package and define class 'main then, define main method inside the class and inside the method. Declare the object of the scanner class and get the size of the array through the object in the variable 'size'. Then, declare two array which are integer type 'a' with the given input size and string type 'word' with the given input size. Set the for loop that get string type array elements from the user and again set two for loop that increase the size of the integer data type array by 1 with the loop iteration. Finally, set the for loop that print the following result.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “java Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers