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

why is a fragmented disk slower than one that is defragmented?

Answers

Answer:

Explanation:

The fragmented program has parts stored all over the hard driven. The computer has to keep on checking for where the next fragment is. All if this takes time especially if the program that you are trying to load is very large.

If the sectors for a program are consecutive, that makes loading a whole lot easier.

what is the term used to describe with you connect your phone to another device to share internet access?

Answers

Answer:

This is hyped as the Internet of Things (IoT). Sometimes also called IoE, the Internet of Everything.

Explanation:

Question # 10
Multiple Choice
Why would a beginning photographer have had a more difficult time learning the art in the early 1900s than now?

Answers

Answer:

cameras were fully Manuel

3.5.7: Rectangle, Part 2 its python coding

Answers

The program which calculates the area of a rectangle written in python 3 is given thus :

def calc_area_rectangle(length, width):

#initialize a function named calc_area_rectangle which takes in two arguments

area= length * width

#the products of the arguments which are the length and width of value of the rectangle is assigned to the variable named area

return round(area, 2)

#the function returns the value of area rounded to 2 decimal places.

print(calc_area_rectangle(10, 20))

#sample run of the program

Learn more :https://brainly.com/question/25162828

most file managers include a way to create a folder through the save dialog box. true or false?

Answers

Answer:

false because most of the file managers just keep Everything organized by dates, years, and everything like that

Explanation:

what did the person using the windows command prompt do during round 1

Answers

The windows command prompt is a an interpreter found in Microsoft computers that executes lines of code or commands given by the user if they are valid.

As a result of this, there are different commands which can be given by the user administrator to the windows command prompt which enables them to:

List the hardware information in the computerShow/Check Networking informationScan for viruses or repair bad system files,  etc

Please note that your question is incomplete, so I gave a general overview which should help you get the right answer.

Read more here:

https://brainly.com/question/12787942

it refers to the kind of activity that you are going to perform or methods of training to used

A.type
B.frequency
C.intensity
D.time

Answers

I believe the correct answer is “type”

how to disappear completely from the internet pc magazine

Answers

In order to disappear completely from the internet, one needs to delete their social media accounts, delete their emails, etc.

The internet is a network of interconnected computer systems. Despite its numerous advantages, it also has several disadvantages and there are some moments when we want to disappear from the internet.

The steps that are needed to disappear from the internet include:

Delete your social network accounts.Delete your email accounts.Use search engines to track your old activities online and delete them.Falsify the accounts that can't be deleted.Unsubscribe from mailing lists.

Read related link on:

https://brainly.com/question/24902823

Which decimal number is equivalent to this hexadecimal number?
F8

A.
24
B.
143
C.
248
D.
264

Answers

Answer:

So, the number 248 is the decimal equivalent of hexadecimal number F8 (Answer).

(F8)16 = (248)10

Step by step solution

Step 1: Write down the hexadecimal number:

(F8)16

Show each digit place as an increasing power of 16:

Fx161 + 8x160

Convert each hexadecimal digits values to decimal values then perform the math:

15x16 + 8x1 = (248)10

So, the number 248 is the decimal equivalent of hexadecimal number F8 (Answer).

please help

suppose you work for a large company create a short memo letting your coworker know that July 3 is also a paid holiday​

Answers

From: Tom Pearson, Manager, District Five

Regarding: New Incoming Manager, Geraldine Hines

Dear Comstock Staff: Beginning March 15, 2018, you will have a new District Five Regional Manager. After 35 years of continuous service, I am leaving all of you to pursue an exciting future.

It has been my pleasure to train my successor, Geraldine Hines, this past year. Geraldine has demonstrated that she shares the company vision to be the employer of choice here in the Valley of the Sun. I am confident that she will lead all of you into the stratosphere as we merge our call centers and expand our donor site availability.

Please give Geraldine the same level of excellence you have given to me, to our staff and to our donors.

Sincerely.

Tom Pearson, Outgoing Manager, District Five

At the top right of the first two pages
only (title page and abstract), insert
page numbers into the header using
lowercase Roman numerals (i, ii).
At the top right of the remaining
pages, insert default page numbering
(1, 2, 3) into the header, beginning
with the number 1 on page 3.

Answers

You don't have the pages. Try re-uploading the question with them.

what is the difference between internal and external css?

Answers

Answer:

Internal CSS are the ones that we can write within the same file i.e the HTML code and CSS code are placed in the same file.

External CSS is that we can write in a separate file than the HTML code i.e the HTML file is separate like(index.html) the CSS file is separate like(style.css).

Explanation:

What is the two’s compliment of -95,-122,-111,-57

Answers

Answer:

-95 0101 1111

-122= 0111 1010

-111= 0110 1111

-57 = 0011 1001

Explanation:

two's Compliment of

- 95 = 0101 1111

-122= 0111 1010

-111= 0110 1111

-57 = 0011 1001

what are the differences between a keyboard and a pointing stick.​

Answers

Answer:

keyboard:

A keyboard is for putting information including letters, words and numbers into your computer. You press the individual buttons on the keyboard when you type. The number keys across the top of the keyboard are also found on the right of the keyboard. The letter keys are in the centre of the keyboard.

pointing stick:

A pointing stick is a small joystick used as a pointing device typically mounted centrally in a computer keyboard. Like other pointing devices such as mice, touchpads or trackballs, operating system software translates manipulation of the device into movements of the pointer or cursor on the monitor.

A color image is made up of red green and blue color combinations 8 bits are used to represent each of the color components how many possible variations of red are there?

Answers

Answer: The three RGB colors are each 8-bits (possible values [0..255], 2 8 = 256) of each of Red, Green, and Blue. The three 8-bit RGB components can create up to 256×256×256 = 16.7 million possible RGB color combinations, called 24-bit "color". Of course, any one real photo image will not use most of these possible colors.

There is possible is the variation of the red color. The RGB is a combination of color. The 8 bit are the division of the 256 are equal to the 16 million.  

What is color?

The term “color” refers to the element of light. Color is part of communication. There are different colors that have different meanings, such as red, which represents love and danger. Colors are divided into different categories such as primary, secondary, and tertiary.

The color is the combination of the RGB colors. The letters R, G, and B stand for Red, Green, and Blue, respectively. The 8 bits for 256 shades of the RGB This means R = 256, G = 256, and B = 256 (256 × 256 × 256) are producing the 16 million colors. The variation of the red is possible to achieve an equal color.

As a result, the variation of the red color are possible are 256.

Learn more about on color, here:

https://brainly.com/question/19580247

#SPJ2

Access your Practice Lab titles Access your exercise content Reports and files Access your settings Access help and support CompTIA Linux Customize or Write Simple Scripts Review Review Well done, you have completed the Customize or Write Simple Scripts Practice Lab. Lab Assessment Test your knowledge on the topics covered in this lab by completing the review questions below. 1 Question What is the extension of a shell script

Answers

Answer:

The extension for a shell script in windows ends with a .ps1 and for the extension for linux it is .sh, not quite sure for OSX.

excuse me i am going into my A levels and i need help in picking what further pure mathematic units i need to pick since i am studying ICT.

Answers

Answer:

i dont know bout math units but subjects for ict include

microcomputer technology, and systems resource management ,computer systems organization.

Explanation:

a _____ is a telecommunications network that connects users and their computers in a geographical area that spans a campus or a city.

Answers

Answer:

(WAN) a wide area network

what is the term for software that is exclusively controlled by a company, and cannot be used or modified without permission?

Answers

Answer:

Proprietary Software

Explanation:

jessica has pinned her favorite applications as icons on her desktop .she always clicks on these icons to work them .which user interface is she using here?

Answers

Answer:

Graphical User Interface

Explanation:

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

Answers

Answer:?

Explanation:?

You have just received a new laptop that you will use on your company network and at home. The company network uses dynamic addressing, and your home network uses static addressing. When you connect the laptop to the company network, everything works fine. When you take your laptop home, you cannot connect to devices on your home network or to the internet.

Required:
What could have been the reason for that?

Answers

Answer:

The network address can be the reason. You need to modify it so you can have access.

the most important keyboard instrument of the romantic period was the

Answers

Answer:

piano

Explanation:

what is the problem here

Answers

Answer:

I think ...............

Which is the most protective and secure anti virus software?

Answers

Answer:

In most cases you should just use an anti virus software that comes with that operating system. But if you would like a third party application try using kaspersky anti virus in my opinion it is simple and user friendly. It can most probably block any malware expect for ones that are new like one day old, it will take somwhile to add it to the database.

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.

what is the name of the method of problem solving that breaks a problem imto smaller problems​

Answers

Answer:

The first thing that came to mind was when my parents tell me "Take it one step at a time" I hope this helps

Explanation:

What appealed to people and especially kids of the 70s and 80s about gaming?
What parts of early gameplay, and which aspects of the games are still relevant today?
What are the major aspects in which gaming has improved since then?

Answers

question 1- it appealed as the ultimate playthings and competed to master them and set the high score, or the record for longest time playing.

question 2- Gameplay is arguably the most important aspect of a game. You can have breathtaking graphics and an enthralling storyline, but if the main game mechanics the player will be performing aren't fun, your project may as well have been a movie.

question 3- Gaming is really a workout for your mind disguised as fun. Studies have shown that playing video games regularly may increase gray matter in the brain and boost brain connectivity. (Gray matter is associated with muscle control, memories, perception, and spatial navigation.)

hope this helps :)

Explain the operation of an electric circuit in terms of voltage, current, and charge.

Answers

If its open its broken if its closed electricity flows

Answer:

If its open its broken if its closed electricity flows

Explanation:

A laptop can be kept on palm to work. [true/false) ​

Answers

Answer:

Explanation:

false

Other Questions
Multiply the following and provide the product in standard from thank you After a 80% reduction, you purchase a new washing on sale for $104. What was the original price of the clothes dryer? PLEASE ANSWER 9 AMD 10 I BEG YOU YOU DONT NO HOW MUCH IT WOULD HELP These paragraphs explain why we can see colors other than green, red, and blueeven though the cones in our eyes are sensitive to just those three colors. Since you have just three types of color detectors in your eyes, it would make sense that the only colors you see would be red, green, and blue. But suppose you're looking at a yellow object. How would your eyes detect a color that isn't an exact match to one of the cones? In this case, the different wavelengths of light for both red and green are reflected into your eyes. The red and green cones send signals of varying strengths to your brain, depending on how excited they are by the different wavelengths. For example, the red cones would be very triggered because more red light is reflected from a yellow object. The green cones would also be triggered, but not as much as the red cones. This triggering of the three different cones to varying degrees is how you see all the different colors. How does this passage of text help readers understand its central idea?A: It defines key terms. B: It tells a story. C: It provides an example.D: It describes a series of steps. A car traveled 63 miles on 3 gallons of gas. What proportion can you set up to determine how many miles m the car can travel on 7 gallons of gas? Write the equation of a line that is perpendicular to y = 3x - 2 and goes through the point (0,5) The function f whose graph is shown has f (x) = 0 at which of the following values of x?A). -2B). -3, -1, and 1 what conclusions can you draw about how the plasma membrane contributes to the function of the cell as a whole write an evidence based claim. will give brainleist which system helps regulate body temperature and water loss? An apple falls from a tree and 2.5 seconds later hits the ground. How fast is the apple falling when it hits the ground? Neglect air resistance.O 2.505O 200 25 1. How were the people of France impacted by the French Revolution? here is a graph of a polynomial function with degree 4 what statements are true about the function? 3/5 7 1/2 2 7/10 When the sun heats up the suface of the water, the water How do you think the companys motto ""Do what you like. Like what you do"" might affect how managers manage? Be specific PLEASEE ANSWER THIS I BEG ILL ADD U AS BRAINLIST! help meee I been stuck on this for the past week Help! 7.05 Semester Test: Music Appreciation - Part 2 (30 POINTS)-1. Name the pitches of these notes in the treble clef.measure 1, beat 12. measure 2, beat 33. measure 4, beat 24. measure 15, beat 15. In order, name all of pitches for the notes in the third measure of the bass clef.6. What is the time signature for this piece?7. How many beats does the first note (in the treble clef) in measure 2 receive?8. How many beats does the second note (in the treble clef) in measure 12 receive?9. How many beats does the rest in measure 16 receive?10. What key is this piece in?(I really need your help, this is the semester test) Arrange the following inequality into slope-intercept form. Then, describe what type of boundary line would be used and where to shade.6x > 2y 5 who was the first presindent of kenya