1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
liubo4ka [24]
2 years ago
9

2.17 LAB: Word frequencies - methods 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.
SAT
1 answer:
pickupchik [31]2 years ago
3 0

Using the knowledge in computational language in JAVA it is possible to write a code that reads a list of words.

<h3>Writting the code in JAVA:</h3>

<em>import java.util.*;</em>

<em>//class name LabClass</em>

<em>public class LabClass{</em>

<em>    //function getFrequencyOfWord with array wordList, ListSize and currWord as parameter</em>

<em>    public static int getFrequencyOfWord(String[] wordsList, int ListSize, String currWord){</em>

<em>        int frequency = 0;</em>

<em>        //for loop for iteration </em>

<em>        for(int i=0; i<ListSize; i++){</em>

<em>            //if current word matches with words present in list</em>

<em>            //then increase the frequency by 1</em>

<em>            if(wordsList[i].compareTo(currWord)==0){</em>

<em>                frequency++;</em>

<em>            }</em>

<em>        }</em>

<em>        //return frequency at last </em>

<em>        return frequency;</em>

<em>    }</em>

<em>    //main function </em>

<em>    public static void main(String[] args) {</em>

<em>        //creating object of Scanner class </em>

<em>        Scanner sc = new Scanner(System.in);</em>

<em>        int size;</em>

<em>        //asking user to input size of list </em>

<em>        System.out.println("Enter the size of list :");</em>

<em>        size = sc.nextInt();</em>

<em>        //creating array of same size as user input size</em>

<em>        String[] wordList = new String[size];</em>

<em>        sc.nextLine();</em>

<em>        //asking user to input array elements </em>

<em>        System.out.println("Enter list elements one by one :");</em>

<em>        for(int i =0; i<size; i++)</em>

<em>        {</em>

<em>            wordList[i] = sc.nextLine();</em>

<em>        }</em>

<em>        System.out.print("\n");</em>

<em>        sc.close();</em>

<em>        //calling function getFrequencyOfWord in every iteration by passing</em>

<em>        //required arguments to it </em>

<em>        for(int i=0; i<size; i++)</em>

<em>        {</em>

<em>            String currWord = wordList[i];</em>

<em>            int count = getFrequencyOfWord(wordList, size, currWord);</em>

<em>            //printing result </em>

<em>            System.err.println(currWord + " : " + count);</em>

<em>        }</em>

<em>    }</em>

<em>}</em>

See more about JAVA at brainly.com/question/12978370

#SPJ1

You might be interested in
Some of the world's most fertile soil is found near
nata0808 [166]
I believe the answer is volcanos
7 0
3 years ago
In a stats class 9 out of 17 students prefer waffles for breakfast. What is the relative frequency of students who prefer waffle
Anvisha [2.4K]
The relative frequency of 9/17 is 53%. 53% of the students prefer waffles.
8 0
3 years ago
Which of the following illustrates the correct placement of information for a single
iren2701 [21]
I think it would be B
3 0
3 years ago
Aubrey invested $7,100 in an account paying an interest rate of 5. 6% compounded quarterly. Assuming no deposits or withdrawals
MatroZZZ [7]

Answer:

6.6%

Explanation:

after 19 years

7 0
2 years ago
Based on the irony in this passage, vonnegut is critiquing a society that.
alexandr402 [8]

Answer: values equality over intelligence.

Explanation:

4 0
3 years ago
Other questions:
  • One good way to cut down on the expenses of technology while in college is to
    5·2 answers
  • Guys im rilly bored right now, so y dont we talk. say anything.
    9·2 answers
  • What negative effect can
    12·1 answer
  • What is common form of water​
    10·1 answer
  • For a population with a mean of μ=45 and a standard deviation of σ=10,
    12·1 answer
  • FREE BRAINLEIAST FOR FIRST GOGOGOGO!!!!
    7·1 answer
  • Sino gusto sumali sa meet ko<br><br> ito code:-<br> zcn-mqti-ssh<br><br><br><br> UwU
    9·1 answer
  • Which of the following details would be considered part of the setting.
    10·1 answer
  • The speaker’s series of exclamations in lines 31-33 (""sweet. . . Pan"") interrupt the pace of the narrative in order to.
    12·1 answer
  • Licensees can generally rely on the statements of the seller (such as in a Seller Disclosure Statement) unless the licensee has
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!