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
mylen [45]
3 years 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]3 years 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
4. When you see ##### in a cell, you should
PolarNik [594]

Answer:

decreace cell width

Explanation:

4 0
3 years ago
Read 2 more answers
A network administrator was testing an IPS device by releasing multiple packets into the network. The administrator examined the
kipiarov [429]

Answer:

c) false positive

Explanation:

An event signaling to produce an alarm when no attack has taken place. False positives are mislabeled security alerts, indicating there is a threat when in actuality, there isn’t. By default, most security teams are conditioned to ignore false positives, In the event of a false positive an IPS will actively stop the normal activity which is likely to negatively impact business functions.

8 0
3 years ago
Read 2 more answers
How do you implement instruction level parallelism
netineya [11]

Answer:

To obtain substantial performance enhancements, we must exploit ILP across multiple basic blocks.

Explanation:

8 0
3 years ago
Calculator is an example of
Shalnov [3]

D. digital

Explanation:

I hope it helps you

7 0
3 years ago
Positive thinkers tend to
andreev551 [17]

Answer:

I would say D hope this helps

3 0
4 years ago
Read 2 more answers
Other questions:
  • Interpersonal skills are extremely important in production management. true or false
    10·1 answer
  • Which examples demonstrate appropriate use of media for a school project? Check all that apply. showing cartoons to teach about
    6·2 answers
  • Describe a scenario for which a find unmatched query could be used.
    12·1 answer
  • The ____ is the configuration of a system documented at the beginning of the project and consists of all necessary system requir
    8·1 answer
  • Know when the double, int, String, and char data types are best used. Example: I would store a social security number in a strin
    7·1 answer
  • Given the following code fragment and the input value of 4.0, what output is generated?
    8·1 answer
  • Referat noaptea la școala cu sfârșit de groază​
    10·1 answer
  • Relationship between application system<br>.and database​
    11·1 answer
  • SOMEONE HELP ME PLEASE <br> What are three reasons technology is beneficial to teens
    11·1 answer
  • Why should you avoid the use of sarcasm, clichés, and idioms in business<br> letters
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!