answer.
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
mylen [45]
1 year ago
8

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: n appears this many times: 1 Ex: If the input is: z Today is Monday the output is: z appears this many times: 0 Ex: If the input is: n It's a sunny day the output is: n appears this many times: 2 Case matters. Ex: If the input is: n Nobody the output is: n appears this many times: 0
Computers and Technology
1 answer:
Svet_ta [14]1 year ago
5 0

Answer:

import java.util.Scanner;

public class NumberOfOccurences {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user inputs

 Scanner input = new Scanner(System.in);

 // Prompt user to enter text

 System.out.println("Please enter the phrase");

 // Store text in a variable

 String phrase = input.nextLine();

 // Prompt user to enter character to be checked

 System.out.println("Please enter the character to check");

 // Store character in a char variable

 char character = input.next().charAt(0);

 // Create and initialize a variable count to zero

 // count will hold the number of occurrences of the character in the phrase

 int count = 0;

 // Loop through each of the character in the string text

 // At every cycle of the loop, compare the character of the string

 // with the character to be checked.

 // If they match, count is incremented

 for (int i = 0; i < phrase.length(); i++) {

  if (phrase.charAt(i) == character) {

   count++;

  }

 }

 // Print out the number of occurrences due to count

 System.out.println(character + " appears this many times " + count);

}

}

Explanation:

The source code file has been attached to this response and has been saved as "NumberOfOccurrences.java". Please download the file and go through the code including the comment. Pay attention to the comments for readability and understandability.

Hope this helps!

Download java
You might be interested in
Cardinality ratios often dictate the detailed design of a database. The cardinality ratio depends on the real-world meaning of t
Otrada [13]

Solution :

ENTITY 1               CARDINALITY RATIO                                     ENTITY 2

1. Student                        1 to many                                     Social security card

                      A student may have more than one          

                     social security card (legally with the

                      same unique social security number),

                     and every social security number belongs

                   to a unique.

2. Student                   Many to Many                                    Teacher

                    Generally students are taught by many

                    teachers and a teacher teaches many students.

3.ClassRoom               Many to Many                                   Wall

                      Do not forget that the wall is usually

                      shared by adjacent rooms.

4. Country                 1 to 1                                             Current President

                       Assuming a normal country under normal

                       circumstances having one president at a

                      time.

5. Course               Many to Many                               TextBook

                        A course may have many textbooks and

                       text book may be prescribed for different

                      courses.

6. Item                             Many to Many                           Order

                        Assuming the same item can appear

                         in different orders.

7. Student                       Many to Many                          Class

                        One student may take several classes.

                        Every class usually has several students.

8. Class                                 Many to 1                             Instructor

                       Assuming that every class has a unique

                        instructor. In case instructors were allowed

                        to team teach, this will be many-many.

9. Instructor                  1 to 1                                             Office

                       Assuming every instructor has only one

                      office and it is not shared. In case of offices

                     shared by 2 instructors, the relationship

                    will be 2-1. Conversely, if any instructor has a joint

                    appointment and offices in both departments,

                    then the relationship will be 1-2. In a very general

                  case, it may be many-many.

10. E-bay Auction item             1-Many                           E-bay bid

                        1 item has many bids and a bid is unique

                        to an item.

7 0
1 year ago
Write code which takes two inputs from the user, a number of sides followed by a side length, then creates a regular polygon wit
Ahat [919]

Answer:

i need free point sorry lol

Explanation:

5 0
1 year ago
Read 2 more answers
The dealer's cost of a car is 85% of the listed price. The dealer would accept any offer that is at least $500 over the dealer's
san4es73 [151]

Answer:

Explanation:

The following code is writen in Python. It is a function called minPrice. It asks the user to input the list price of the vehicle and then multiplies that by 0.85 in order to get the dealer's cost. Then it adds 500 to that price and returns it to the user as the minimum price that the dealer would accept for the car.

def minPrice():

   list_price = input("Please enter the list price of the car: ")

   dealers_cost = int(list_price) * 0.85

   min_accepted_price = dealers_cost + 500

   print(min_accepted_price)

5 0
1 year ago
When a typeface does not have any extra embellishments on the top and bottom of the letterforms, it is called a ________ font?
Harrizon [31]

The font that does not have extra embellishment, as well as its top and bottom of the letter forms is the sans serif. This font does not provide any features that are extended and that they are comprised of less line width.

5 0
1 year ago
Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
irinina [24]

Answer:

b. The Hello timer as configured on the root switch.

Explanation:

There are differrent timers in a switch. The root switch is the only forwarding switch in a network, while non root switches blocks traffic to  prevent looping of BPDUs in the network. Since the root switch is the only forwarding switch, all timing configuration comes from or is based on the configuration in the root.

The hello timer is no exception as the nonroot switch only sends 802.1D DTP hello BPDU messages forwarded to it by the root switch and its frequency depends on the root switch hello timer.

8 0
2 years ago
Other questions:
  • Is used to process certificates and private/public key information?
    12·1 answer
  • Which act was used to penalize Sara? Sara was found to be in possession of a controlled substance for which she had no justifica
    5·1 answer
  • _____________ involves the deployment of malware that secretly steals data in the computer systems of organizations, such as gov
    13·1 answer
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    10·1 answer
  • A 1.17 g sample of an alkane hydrocarbon gas occupies a volume of 674 mL at 28°C and 741 mmHg. Alkanes are known to have the gen
    14·1 answer
  • The variable grade can have any real number value from 0 to 100. Ask the user to enter a grade in numerical form. Write an if-el
    9·1 answer
  • A mobile device user has tried to install a new app numerous times without success. She has closed all unused apps, disabled liv
    7·1 answer
  • CHALLENGE ACTIVITY 3.7.2: Type casting: Reading and adding values.
    10·1 answer
  • Exercise 4: Bring in program grades.cpp and grades.txt from the Lab 10 folder. Fill in the code in bold so that the data is prop
    12·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!