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
alexandr402
1 month 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:
oksian1 [950]1 month ago
5 0

Answer:

import java.util.Scanner;

public class NumberOfOccurences {

public static void main(String[] args) {

 // Instantiate a Scanner object for user Input

 Scanner input = new Scanner(System.in);

 // Ask user to enter text

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

 // Save the text in a variable

 String phrase = input.nextLine();

 // Ask user to input character for checking

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

 // Capture character in a char variable

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

 // Initialize count variable to zero

 // Count will store occurrences of the character in the phrase

 int count = 0;

 // Iterate through each character in the string

 // For each loop, compare the character of the string

 // with the character being checked.

 // If there's a match, increment count

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

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

   count++;

  }

 }

 // Display the count of occurrences

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

}

}

Explanation:

The code has been shared in the response as "NumberOfOccurrences.java". Kindly download the file and review the code along with the comments. Pay close attention to the comments for clarity and comprehension.

Hope this aids you!

Download java
You might be interested in
A user calls the help desk and reports that the workstation, when powering up, displays error messages about an invalid system d
ivann1987 [1066]

Answer:

Option (A) is the correct choice.

Explanation:

The situation describes an invalid boot disk error occurring during startup, indicating that the system fails to recognize the hard disk necessary for booting.

MBR / GPT is the partition layout that holds the essential code for system startup. Occasionally, the partition files that contain this code may become corrupt, causing an invalid boot disk error during the boot process.

Therefore, the most fitting answer is option (A).

The remaining choices are incorrect for these reasons:

  • If the boot system malfunctions, it cannot produce an invalid boot disk error.
  • If the files of the operating system are corrupted, the error will pertain to missing files.
  • A device driver cannot influence the system's booting process.
5 0
2 months ago
Write a function called simulate_several_key_strikes. It should take one argument: an integer specifying the number of key strik
oksian1 [950]

Answer:

The code for the solution is implemented using Python 3.

  1. import random
  2. import string
  3. def simulate_several_key_strikes(l):
  4.    char_set = string.ascii_lowercase
  5.    return ''.join(random.choice(char_set) for i in range(l))
  6. print (simulate_several_key_strikes(10))

Explanation:

This program is designed to create random characters, and the quantity of characters produced is determined by the user's input. Therefore, it is necessary to import the random library (Line 1). Additionally, we incorporate the string module to access its associated method for generating English letters (Line 2).

Then, we define the function simulate_several_key_strikes that accepts one parameter, l. Inside this function, the ascii_lowercase method is utilized to establish the character set of lowercase letters, which is stored in the variable char_set (Line 5). The random.choice method randomly selects a character from char_set, concatenating it with an empty string (Line 6). A for-loop is utilized to produce a total of l characters, generating the final output.

To test the function, we input 10 as an argument, producing a sample output such as:

xuiczuskoj

7 0
2 months ago
While Angela is making modifications to Katie’s Word document, she would like to inform Katie of the reasoning for the change. W
ivann1987 [1066]

Answer:

Using email would be effective.

6 0
2 months ago
Other questions:
  • Splunk In most production environments, _______ will be used as the source of data input?
    12·1 answer
  • PLEASE HELP!!~~
    7·1 answer
  • Meadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual
    6·1 answer
  • When performing actions between your computer and one that is infected with a virus which of the following offers no risk becomi
    5·1 answer
  • Write a loop that prints each country's population in country_pop. Sample output for the given program.
    6·1 answer
  • On the planet Sigma, robots excavate chunks of a very precious cristaline. These chunks can be divided into smaller part only on
    15·1 answer
  • explain why entrepreneurial activities are important to social development and progress of the econo​
    9·1 answer
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    7·1 answer
  • Drag each label to the correct location on the image.
    11·1 answer
  • An automobile battery, when connected to a car radio, provides 12.5 V to the radio. When connected to a set of headlights, it pr
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!