Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2

Answers

Answer 1

Answer:

import java.io.*;  

public class Main {

   public static void main(String[] args) throws IOException {

       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

       String s;

       while ((s = in.readLine()) != null) {

           int total = 0;

           for (char character : s.toCharArray()) {

               if (s.charAt(0) == character) {

                   total++;

               }

           }

           System.out.println(total - 1);

       }

   }

}

Explanation:

We start the program by using the BufferedReader which will allow input from the user.

Then, we create a variable String that will take the input from the user.

Since the problem is asking us for the total number of times that the specified character appeared in the String, we will have to iterate over that String and count every time the character is found.

For this, I initialized an integer variable total, that takes count every time the character is found.

Using a for each loop, I converted the string to a character array (e.g. instead of a String "Monday", it will now look like {"M", "o", "n", "d", "a", "y"). It will iterate for each character it finds and checks if the character at position 0 is the same as the character at position i.

If the condition is true, then the total will increment by one.

But the problem is, since we converted the string into a character array to validate each character, the initial character will also add to the sum. So for "n Monday", it will take the first n, and add the total + 1.

Without specifying total - 1, "n Monday" will output 2 since there are two total "n".

There is a limitation, which wasn't specified in the problem statement anyway, but it's good to be aware of in case you need to solve it. If you want to check all of the characters that must equal the character you want to validate, irrespective of upper or lowercase, you will have to convert the string to lowercase first, so that the program will take the uppercase letters into account as well.

For that, before the for each statement, simply add s = s.toLowerCase();


Related Questions

What language do programmers use to communicate with a computer?

Input code
Linguistic code
Programming code
Virtual code

Answers

Answer:

I would say programming code

Explanation:

Since its a system of rules written in a particular programming language

The language that programmers use to communicate with a computer is called "Programming code".

The correct option is C.

Programming code is the language that is used by developers to create software programs, applications, and websites. These languages are based on a set of instructions that tell the computer what to do.

Programming languages can be divided into two categories: low-level and high-level.

Low-level languages are closer to the binary code that computers use to execute instructions.

High-level languages are more abstract and easier for humans to understand and use.

Examples of high-level languages include Python, Java, JavaScript, and C++.

Programmers use programming languages to create algorithms and procedures that the computer can follow to complete tasks. This involves writing code that is syntactically correct and logically sound. Once the code is written, it must be compiled or interpreted by the computer so that it can be executed.

Know more about programming language,

https://brainly.com/question/23959041

#SPJ3

Language modeling incorporates rules of __. Select all that apply.

A. story structure

B. grammar

C. dictionary definitions

D. pronunciation patterns

Answers

Language modeling incorporates rules of grammar and pronunciation patterns

Language modeling  is simply known to use rules of grammar, known pronunciations, and other patternsIt seeks to know the given probability distribution of all linguistic units such as words, sentences.  is main work is to predict the next word that is to come in a document.It makes use of grammar principles and the various forms of pronunciation in its task.

Conclusively, we can say that Language modeling incorporates rules of grammar and pronunciation patterns

Learn more from

https://brainly.com/question/6214562

based on mla guidelines, what is the correct margin width?

Answers

Answer:

Leave 1 inch margins on each side.

write down the steps to start computer.​

Answers

Answer:

To start a Desktop PC:

Ensure the PC is plugged in.  

Press the power button.  

Let the computer start.

When prompted, insert the password if you have one set.  

To start a laptop:

Press the power button.

Let the laptop start.

When prompted, insert the password if you have one set.

the first fully 64 bit compatible version of android is:

Answers

Answer:

Android 5.0 Lollipop, I hope this helped.

Answer:

The version of the first 64 bit andriod ia the version called: Andriod 5.0 lolipop

Hope this help please give the brainliest award.

you type out a few sentences in an ms word file, and save it on your desktop. how is this data stored in the computer?

Answers

When one is  typing on MS word and one save the file, this data would be stored as combination of 1s and 0s in the computer.

Computer data storage can be regarded complex system, immediately a data is saved then;

The first be converted to simple numbers of 1s and 0s , this number are very easy for a computer to store and these number are regarded as Binary Numbers and all letters as well as photographs are converted to numbers,

The hardware will record this saved numbers inside the computer.

These numbers are then  organized and transferred to temporary storage which be manipulated by programs, or software.

Therefore, data are been stored as 1s and 0s in the computer.

Learn more at:https://brainly.com/question/21571591?referrer=searchResults

Which options are available in the Conditional Formatting dialog box?

Answers

Answer:

all but b are correct.

Explanation:

what is the most common type of storage device for transferring files from one computer to another?

Answers

Answer:

USB flash drives is the most common type of storage device for transferring files from one computer to another

an error occurred while loading a higher quality version of this video

Answers

Answer:?

Explanation:?

1. Define the term Intranet.
2. List three advantages of the intranet.
3. List three disadvantages of the intranet.
4. Briefly define the term extranet. 2marks
5. List three advantages of the extranet.
6. List two disadvantages of the extranet.

Answers

Answer:

1.a local or restricted communications network, especially a private network created using World Wide Web software.

2.Enhanced employee engagement.

Increased productivity.

Better connection and collaboration of distributed employees.

Streamlined communication of change management.

Establishing and reinforcing a strong company culture.

Efficient time management.

3.Costly and timely implementation. Intranet can be very costly and time-consuming to implement.

Complexity and heavy admin burden.  

Poor user experience.  

Low user adoption.  

Time-consuming information search.  

Internal use only.  

Lack of employee advocacy.  

Hard to measure success and effectiveness.

4.An extranet is a private network that enterprises use to provide trusted third parties -- such as suppliers, vendors, partners, customers and other businesses -- secure, controlled access to business information or operations.

5.Information sharing is simple. Without a client extranet, you're likely sharing files with outside parties via email.  

Documents are safe and secure.  

Project management is easy.  

Setup and training require little to no IT involvement.  

Professional branding makes a great impression.

6.Cost. It is no doubt that extranet involves direct expenses such as hardwares, softwares and training of employees.  

Maintenance. Both extranet implementation and maintenance is made expensive within an organization.  

Dependency.  

System Protection.  

Communication Delay.  

User Friendliness.

Explanation:

Difference between batabse and database management system

Answers

Answer:A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a database management system (DBMS). ... The data can then be easily accessed, managed, modified, updated, controlled, and organized.

Explanation:A database could be grades that students get at school and to manage it we can use a spreadsheet program like excel

n (m,n) correlating branch predictor uses the behavior of the most recent m executed branches to choose from 2m predictors, each of which is an n- bit predictor. A two-level local predictor works in a similar fashion, but only keeps track of the past behavior of each individual branch to predict future behavior.There is a design trade-off involved with such predictors: correlating predictors require little memory for history, which allows them to maintain 2-bit predictors for a large number of individual branches (reducing the probability of branch instructions reusing the same predictor), while local predictors require substan- tially more memory to keep history and are thus limited to tracking a relatively small number of branch instructions. For this exercise, consider a (1,2) correlating predictor that can track four branches (requiring 16 bits) versus a (1,2) local pre- dictor that can track two branches using the same amount of memory. For the fol- lowing branch outcomes, provide each prediction, the table entry used to make the prediction, any updates to the table as a result of the prediction, and the final mis- prediction rate of each predictor. Assume that all branches up to this point have been taken. Initialize each predictor to the following:

Answers

Answer:

a

Explanation:

the superclass javax.servlet.http.httpservlet was not found on the java build path

Answers

Answer:

follow this link https://stackoverflow.com/questions/22756153/the-superclass-javax-servlet-http-httpservlet-was-not-found-on-the-java-build

Explanation:

nice

Match the letter with the corresponding Workspace Area

Options :

-workspace settings

-options bar

-menu bar

-toolbar

Answers

The workspace areas described are editing tools of the photoshop program

The options described below are part of the Adobe Photoshop program for image and photo editing.

Workspace settings: It is a bar to configure the general aspects of the workspace in which an image is going to be edited or created.

Options bar: It is a bar located in the upper part (second row) of the document in which we have different options depending on the tool of the toolbar that we choose.

Menu bar: It is the bar located at the top (first row) in which we find different options such as:

FileEditionImageCapTextSelectionFilter3DViewWindowHelp

Toolbar: It is the bar located on the left side of the screen where we find different editing tools for our file, such as:

MoveMagnetic loopTrimDropperBrushDraftDegradedFeather

Note: This question is incomplete because the information is incomplete. However, I can answer based on my previous knowledge.

Learn more in: https://brainly.com/question/24964958

Complete the sentence.
A(n)
A. Accessibility document
B. User manual
C. Code library
D. Version control document keeps track of the version numbers of an app and what changes were made váth each
version

Answers

Answer: D Version control document

Explanation: right on cs

A version control document keeps track of the version numbers of an application and what changes were made in each version.

What is version control?

Version control can be defined as a process through which changes to a document, file, application and software codes over time, are tracked, recorded and managed, especially for easy recall and modification of specific versions in the future.

In Computer technology, an example of a version control system that is commonly used by software developers across the world is Git.

Read more on version control here: https://brainly.com/question/22938019

#SPJ2

what does a exponent do in excel ?​

Answers

Answer:

Exponents in Excel are one of the oldest concepts in Mathematics and are a very powerful one as you have to deal with powers. They are basically a shorthand notation for repetition or to depict how many times a number is getting multiplied to itself.

Explanation:

Consider the plain text ALLTHEBEST with key values 4,19,3,2,3,4,12,5,11,4 what will be the cipher text after applying vigenere cipher.

Answers

hi bae systems applied to the relationship

Why is the Game Design Document called a ""living"" document AND why is this important?

Answers

Answer:

documentation

Explanation:

Because it gives the instructions rules and every detail about the game with anything in the real world with computers documentation is extremly important  

Which of the following are advantages of using meaningful names for variables when writing a program? Select two answers.
1. Less variables will be required as the existing ones can be renamed throughout the program.
2. It is easier for a person reading the code to identify the purpose of a variable and follow the logic of the program.
3. It is simpler for the compiler to compile the program, meaning wait times and errors are reduced.
4. The programmer is less likely to make a mistake and use a variable for the wrong purpose.

Answers

Answer:

The answer is 2 and 4, please give brainliest award.

____ describes the period of time in a twenty-four-hour period that is spent at work.

Answers

I believe "Work-Shift" should be in the blank

Easy Question I will make you brainless Just answer this 10 question!!.​

Answers

Answer:

Utility knife - basket

Old newspaper - basket

Strong scissor-Sc

Clean soda can-Sc

Stapler - B

Scissor-basket

Push pin - Sc

Masking tape - Sc

Pin black-Sc

Glue-basket

what is the name of the fields in an x.509 digital certificate that are used when the parties negotiate a secure connection?

Answers

Answer:

Image result for what is the name of the fields in an x.509 digital certificate that are used when the parties negotiate a secure connection?

Common applications of X. 509 certificates include SSL/TLS and HTTPS for authenticated and encrypted web browsing, signed and encrypted email via the S/MIME protocol, code signing, document signing, client authentication, and government-issued electronic ID.

Explanation:

what is an indication that malicious code is running?

Answers

Answer:

If you are running Windows check task manager and see if any background process if running if there is a background process of command prompt or powershell, there is a chance that there is a backdoor running in your system, you can just right click and end the task it should just kick the hacker off the server.

please give brainliest

a modem is required for ________________ internet access.

Answers

Broadband I believe!

what level of system and network is required for cui

Answers

Answer:

CUI will be classified at a “moderate” confidentiality level and follow DoDI 8500.01 and 8510.01 in all DOD systems. Non-DoD systems must provide adequate security with requirements incorporated into all legal documents with non-DoD entities following DoDI 8582.01 guideline

Explanation:

You have a 7 GHz dual core processor. How many decisions can the processor

make in one second? *


PLEASE HELP 10 points

Answers

The unit that you're asking about (GHz) refers to the frequency.
Frequency is the reciprocal of time.
This means that it gives the measure of work done per unit time.
For example, suppose you can throw two apples in one second then the frequency of your throw is 2Hz or 2Hertz.

what safety do you need to have ready to start a device repair?

Answers

Answer:

Make sure to have the right tools for the right job. if you don't it would be probably best to send it to a shop to get fixed.

I will make you brainless Just answer this question!!!!

A. Arrange the follow stpes chronologically.Write A the first step,Bfor the second and so on...​

Answers

Answer:

6, 8,5,3,4,1,9,2,7

Explanation:

Just like that

Answer:

6, 8, 1, 3, 4, 2, 9, 5, 7

What refers to the place you drag and drop blocks to create instructions in Scratch?

A.
playground

B.
sprite

C.
editor

D.
environment

Answers

Answer:

It is called the editor script area, hence the name is where you create and edit code.

Hope this help please give the brainliest award.

what does your dns server might be unavailable mean?

Answers

Answer:

flush your dns

Explanation:

Other Questions
cantankerous means:O retroactiveO diaphanousO stubbornO palliative Imagine a small, bright object appeared in the sky, moved along with a nearby constellation, and then disappeared a year later. Scientists in China Persia Europe,Nand Central America observed the event. Where did this phenomenon most likelyoccur. How do you know? (Please help me) Find the area and perimeter.5.6 cm Solve the system of equations: 2x + 5y = -1 and 3x - y = 7 A. = 7, y=6 B. x = 2, y = -1 C. X = 2, y = 1 D. None of the above The novel Orphan Train is a historical fiction novel. What connection(s) can you make so far to the novel and true American history? HELP LAST ATTEMPT MARKING AS BRAINLIEST PLS ANSWER QUICKLY!!!If point P is between A and M, which of these is true?A. AM + AP = PAB. AP + PM = AMC. PA + AM = PMD. AM + PM = AP I need help with this please Nyesha owns a lawn service company. Currently it takes her 50 hours a week to service all of hercustomers. To reduce the number of hours a week she needs to work, Nyseha hires Shantese tohelp her. While Nyesha was on vacation, Shantese was able to complete all of the work in 60 hours.If Shantese and Nyesha work together, after Nyesha returns from facation, how long will it takethem to service all their customers? Can someone help me solve x? Dilogo variable Son variables o son suposiciones Question 4 (2 points)A pamphlet is considered to be one of the earliest forms ofO religious literatureO protest literatureAmerica's first dramatic literaturean Appeal to Authority/A Credible Source (Ethos) han once.) BLOWING TAPPING SHAKING PLUCKING -1. Blowing a comb wrapped with paper 2. An empty bottle filled with sand 3. Pat's cover being hit by a stick repeatedly 4. A stretched nylon being plucked 5. Tables being tapped maling Rhythmir Melodic Accompanimentplease help please i need your help i need your help and thank you ^_^^_^^_^ what are your political beliefs? There are 450 kids in 6th grade. out of these kids 40% chose French as their connection. how many kid chose French? Simplify 5 to the power 3 over 5 to the power 7 what PREPARED ponyboy and johnny to be heros robby raises holstein and jersey cows on his farm in the ratio of 7:5 if he has a total of 48 cows on his farm how many holstein cows does he own? A project calls for three pieces of wood. The longest piece must be twice the lengthof the middle-sized piece. The shortest piece must be 10 in. shorter than the middle-sized piece. If a board 70 in. long is to be used, how long can each piece be? The Students on each team who drew the greatest number will be the captain of that team. Place the players of the Tigers team in order from Least to Greatest.Who was the captain of the Tiger Team?