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
astra-53 [7]
3 years ago
6

Write a Console Java program that asks the user to enter one sentence on the keyboard. Output on the console:

Computers and Technology
1 answer:
Nady [450]3 years ago
6 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 function

String sentence;  //to store the input sentence

int i, length;  //declare variables

int count[] = new int[256];  //creates a counter array

  Scanner input = new Scanner(System.in);  //creates Scanner class object to accept input from user

       System.out.println("Enter a sentence: ");  //prompts user to enter a sentence

       sentence = input.nextLine();  //scans and reads the entire sentence string from user

   String[] words = sentence.split("\\s+");  //splits the sentence into an array with separator as one or more white spaces and stores this array in words

   System.out.println("Number of words: " + words.length);  //display the number of words in sentence by using length which returns the length of the words array

     sentence = sentence.toLowerCase();  // converts the sentence into lower case to ignore case sensitivity

     sentence = sentence.replaceAll("\\s+","");  //removes the empty spaces from sentence

     length = sentence.length();  //stores the length of the sentence string into length variable

       for (i = 0; i < length; i++) {  //iterates through the length of the sentence

           count[(int) sentence.charAt(i)]++;        }  //counts occurrence of each alphabet in the sentence and stores it in count array

       for (i = 0; i < 256; i++) {  displays occurrence of alphabet in sentence

           if (count[i] != 0) {  //if count array is not empty

               System.out.println((char) i + "-" + count[i]);  }}}}

//prints each alphabet and its count

           

Explanation:

The program prompts the user to enter a sentence. Suppose the user enters "We won" so

sentence = "We won"

Now this sentence splits into an array with white space as separator and stored in words array. So words array has two words of sentence now i.e. "We" and "won"

Next words.length is used to return the length of words array. So length of words array is 2 hence

number of words = 2

Next the sentence is converted to lower case and spaces are removes so sentence becomes:

wewon

sentence.length() returns the length of sentence which is 5.

Next the for loop is used. At each iteration of this loop occurrence each character of sentence is added to the count[] array. charAt() is used to return a character at each index position of string. So the frequency of every character is counted and stored in count array.

Next is a for loop that is used to display each alphabet in the sentence along with its frequency in alphabetic order.

Hence the entire program gives the output:

Number of words: 2                                                                                                             e-1                                                                                                                            n-1                                                                                                                            o-1                                                                                                                            w-2

The screenshot of the output of example given in the question is attached.

You might be interested in
A point is named by a lowercase letter. <br> a. True<br> b. False
Alik [6]
That is B False m8 that means mate btw xD please say thank you :P
4 0
3 years ago
Read 2 more answers
What is the Moore's law
Nadya [2.5K]

Answer:

Hi, in the law of Moore we can express aproxitmaly for each <em>two years</em> is duplicated the number of transitors in a microprocessor.

Explanation:

In around 26 years the number of transitors has increased about 3200 times, a transitor is a way to regulate the current voltage flow and can be act like a <em>switch</em> for an electronic signal.

I hope it's help you.

4 0
3 years ago
Which options are available in the Conditional Formatting dialog box? Check all that apply.
IrinaVladis [17]

Answer:

There are several options within this dialog box for applying Conditional Formatting ☼ Click the desired option under the Select a Rule Type list. ☼ The bottom portion of the dialog box will change depending on the Rule Type that was selected. ✞ Click Format Only Cells That Contain under Select a Rule Type

6 0
3 years ago
Read 2 more answers
you use the read csv() function to import the data from the .csv file. assume that the name of the data frame is bars df and the
kumpel [21]

Since you use the read_csv() function to import the data from the .csv file, the code chunk that lets you create the data frame is option C:  flavors_df <- read_csv("flavors_of_cacao.csv")

<h3>What is the aim of chunking?</h3>

Chunking aids in this process by dividing lengthy informational passages into smaller, easier-to-remember bits of information, especially when the memory is being challenged by conflicting inputs.

An R code chunk is a portion of executable code. Calculations will be repeated if the document is reproduced. The benefit of code chunk technology is the decreased possibility of mismatch.

The data frame can be created using the code chunk flavors df - read csv("flavors of cacao.csv"). In this section of code:

The data frame with the name flavors df will hold the information.

  • The assignment operator - is used to give the data frame values.
  • The function read csv() will import the data into the data frame.
  • It read "flavors of cacao.csv" in the file name.
  • the argument that the csv() function accepts.

Learn more about Coding from

brainly.com/question/25525005
#SPJ1

See full question  below

You use the read_csv() function to import the data from the .csv file. Assume that the name of the data frame is flavors_df and the .csv file is in the working directory. What code chunk lets you create the data frame?

Single Choice Question. Please Choose The Correct Option &#x2714;

A

read_csv(flavors_df <- "flavors_of_cacao.csv")

B

read_csv("flavors_of_cacao.csv") <- flavors_df

C

flavors_df <- read_csv("flavors_of_cacao.csv")

D

flavors_df + read_csv("flavors_of_cacao.csv")

5 0
1 year ago
What is the relationship between CAD and CIM ?
Marat540 [252]
<span> CAM( computerised Aided Manufacture) is when you have workers being helped by computerised tools, CIM (computerised intergated manufacture) is when the whole process is computerised, in manufacture this usually uses robotic arms. These can manufacture 24/7 in needed, they can work very accurately ( they are faster and stronger than a human arm) </span>
5 0
3 years ago
Read 2 more answers
Other questions:
  • What contains the computer brain the central processing unit
    8·2 answers
  • What is Hadoop?
    15·1 answer
  • On a network, which protocol is responsible for dividing files into chunks, adding headers containing information for reassembli
    10·1 answer
  • How long does it take to be placed in a class on flvs?
    14·1 answer
  • Power point presentation make use of pages known as
    9·2 answers
  • Illustrator : how do you edit a swatch ?​
    12·1 answer
  • I really need this done Thank you!!
    6·1 answer
  • What is the purpose of the ISOWEEKNUM function? determines how many workdays are in a certain week determines how many workdays
    12·2 answers
  • True or False? Popular sites are always mean accurate.
    14·2 answers
  • What is another term used for next generation firewalls
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!