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
solmaris [256]
3 years ago
5

Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a

n integer indicating the number of words that follow. Assume that the list will always contain fewer than 20 words.
Ex: If the input is:
5 hey hi Mark hi mark
the output is:
hey 1
hi 2
Mark 1
hi 2
mark 1
Hint: Use two arrays, one array for the strings and one array for the frequencies.

Computers and Technology
1 answer:
katrin2010 [14]3 years ago
4 0

Answer:

Here is the JAVA program:

import java.util.Scanner;   //to accept input from user

public class Main {  //class name

  public static void main(String[] args) {  //start of main method

      Scanner input = new Scanner(System.in);  //creates Scanner object

      int integer = input.nextInt();  //declares and reads the integer indicating the number of words

      String stringArray[] = new String[integer]; //creates array to hold strings

      for (int i = 0; i < integer; i++) {  //iterates through the array

          stringArray[i] = input.next();         }  //reads strings

      int frequency[] = new int[integer];  //creates array for frequencies

      int count;         //declares variable to count frequency of each word

      for (int i = 0; i < frequency.length; i++) {  //iterates through the frequency array

          count = 0;  //initializes count to 0

          for (int j = 0; j < frequency.length; j++) {  //iterates through array

              if (stringArray[i].equals(stringArray[j])) {  //if element at ith index of stringArray is equal to element at jth index of stringArray

                  count++;                 }            }  //adds 1 to the count

          frequency[i] = count;      }  //adds count to ith index of frequency array

      for (int i = 0; i < stringArray.length; i++) {  //iterates through the array

          System.out.println(stringArray[i] + " " + frequency[i]);         }    }    } //displays each word in stringArray and its corresponding frequency in frequency array

Explanation:

I will explain the program with an example:

let integer = 3

for (int i = 0; i < integer; i++) this loop is used to read input strings into stringArray.

At first iteration:

i = 0

0<3

stringArray[i] = input.next(); this reads a word and stores it to ith index of stringArray. Lets say user enters the string "hey" so hey is stored in stringArray[0]

i++ becomes i = 1

At second iteration:

i = 1

1<3

stringArray[i] = input.next(); this reads a word and stores it to ith index of stringArray. Lets say user enters the string "hi" so hi is stored in stringArray[1]

i++ becomes i = 2

At third iteration:

i = 2

2<3

stringArray[i] = input.next(); this reads a word and stores it to ith index of stringArray. Lets say user enters the string "hi" so hi is stored in stringArray[2]

i++ becomes i = 3

Now the loop breaks as i<integers evaluates to false.

Next the outer loop for (int i = 0; i < frequency.length; i++)

and inner loop for (int j = 0; j < frequency.length; j++)  iterate through the array and if condition if (stringArray[i].equals(stringArray[j])) checks if any of the words at specified indices is equal. This is used in order to check if any word in the list comes more than once. So if any word occurs more than once in the array, then its count is increased each time and the count value is stored in frequency[] array to store the count/frequency of each word in the stringArray. Since hey occurs once so its count is set to 1 and hi occurs twice so its frequency is set to 2. So the output of the entire program is:

hey 1

hi 2

hi 2

The screenshot of the program along with its output with the given example in question is attached.

You might be interested in
Lisa has a section of her document that she would like to include in the index. Which option should Lisa choose?
kupik [55]

Answer:

For including a part of the text within the index, you need to make use of the Mark Entry option. And here you can fill the required information for curating your index, you need to just follow the instruction as required, and you will be fine.

Explanation:

Please check the answer.

8 0
3 years ago
Alex, a web designer, is assigned the task of creating a mobile device-friendly website for a leading fashion outlet called AllS
Katyanochek1 [597]

Answer: Pulldown menus

Explanation:

Pulldown menus refer to the graphical control element, that is identical to a list box, which enables user to be bake to select one value from a list.

They're regarded as the menu of options that will appear when an item is selected with a mouse. In this case, the item that the user selected will show at the top of the display screen, while the menu appears will show below it.

Therefore, Alex should use the pulldown menus to hide the long list of hypertext links so that it appears only in response to a tap of a major heading in the navigation list.

6 0
3 years ago
I’m quitting this thing so I’m giving all my points away which are 218!!! I’m still gonna have more tho just in case I ever need
Sedaia [141]

Answer:

skdjdishsjsbsisjsjsjsjsnssnsjsjsjsjsjsjjskdxkjdsisi

4 0
3 years ago
Read 2 more answers
Windows doesn't have a network profile for this device printer
Arte-miy333 [17]
It's common problem if you connect new devices to the laptop with fresh Windows. There are two ways how to solve your problem:
1. You can use hardware troubleshooter to define the problem. You should type "Troubleshooting" in search. Then click on "Hardware and Devices" and start troubleshooting. 

2. You can solve it by yourself by uninstalling existing drivers. Go to "Device Manager" and search for "USB Drivers". Expand it and select "Uninstall". Then go to manufacturer's website and download the latest stable driver for your device.


3 0
3 years ago
Quinn recently launched a Display campaign for his women's clothing store. Since the launch, his website traffic has increased,
photoshop1234 [79]

<u>Full question:</u>

Quinn recently launched a Display campaign for his women’s clothing store. Since the launch, his website traffic has increased, but sales have remained flat. Which story shows Quinn using remarketing to drive action?

A. Quinn remarkets using his original business objectives and campaigns, with new users from an uploaded compatible list. By leveraging existing materials, he aims to extend his reach while saving cost.

B. Quinn creates a list of cart abandoners that identifies users who visited his website, considered buying his clothing, but didn’t purchase. He shows them an ad with a promotional discount code.

C. Quinn uses the In-Market audience segment for baking supplies with the intent of reaching potential customers while they’re actively browsing for women’s apparel and are close to a conversion.

D. Quinn creates a custom audience segment using keywords and URLs as inputs. He hopes to extend his audience to customers interested in women’s accessories.

Option B

Quinn creates a list of cart abandoners that identifies users who visited his website, considered buying his clothing, but didn’t purchase. He shows them an ad with a promotional discount code shows Quinn using remarketing to drive action

<h3><u>Explanation:</u></h3>

Remarketing is a manner of online advertising that allows sites to exhibit targeted ads to users who have previously hit their site. Remarketing consists of practicing special tracking code to order cookies on the browsers of somebody hitting your website and then assisting ads to those with that cookie.

Because Quinn is dispensing promotional discount code ads to the personality who hit his website, consider purchasing his clothing, but didn’t acquire. Remarketing lets you target those people who have toured your website or entered your app.

4 0
4 years ago
Other questions:
  • What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? Group of answer choices
    10·1 answer
  • Overcoming the fundamental attribution error requires making an effort to shift an external attribution into an internal attribu
    15·2 answers
  • A mobile device is freezing almost daily. The device remains powered on and the screen illuminated. The user restarts the device
    13·1 answer
  • Software for pcs contains a ________ program that guides you through the installation process.​​
    7·2 answers
  • Reasons for the growth of decision-making systems include:
    13·1 answer
  • Business customers pay $0.006 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0
    11·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    9·1 answer
  • CC stand for.....in the email platform?
    12·2 answers
  • Name two reasons why we don't make use of optical drives that often any more​
    5·1 answer
  • Silicone rubber and urethane caulks generally give the ____________ overall performance for exterior building envelope applicati
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!