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
A computer may keep freezing if it's software is up-to-date? <br> True <br> False
tester [92]

Answer:

false

Explanation:

6 0
4 years ago
A video games sell for $59.99..
Neko [114]
Well, in texas the sales tax is 8.25%
So I'll use that example. <span>(A)
</span>sales tax = 8.25% of $59.99 = (8.25/100) * $59.99 = $4.95 <span>
(B)
</span>Price with tax = selling price + sales tax = $59.99 + $4.95 = $64.94 <span>
</span>
5 0
3 years ago
Help need urgently answer ​
skad [1K]

Answer:

Explanation:

b

6 0
3 years ago
Read 2 more answers
What is the slogan of the sociological school of criticism ?​
mafiozo [28]
Sociological criticism focuses on the relationship between literature and society, the social function of literature
7 0
3 years ago
Designing the right elements for the tasks that the user is attempting to perform is called ________.
skelet666 [1.2K]

Answer:

Interface design

Explanation:

INTERFACE DESIGN are design that are carried out on either a computer or a mobile phone or other devices that will suit the users by designing the style of the devices and how the device will look like which will inturn enable the user to easily carried out or performed any tasks they are want to perform with easy and without any lapses which is why it is important for INTERFACE DESIGN to be design with the right tools that the user can easily understand in order to access and perform their tasks effectively.

6 0
3 years ago
Other questions:
  • Two users, UserA and UserB, are engaging in secure communication using only asymmetrical encryption. UserA needs to send a secur
    11·1 answer
  • One reason for using social media is to develop social and professional contacts. True or False?
    9·1 answer
  • Which of the following is 1000 of a second​
    15·1 answer
  • Sammy created a new logo for his client enlarged to use on a billboard ad. Now Sammy needs to redo the logo. What should he do t
    5·1 answer
  • 97 points pleaseeee helpppp
    8·2 answers
  • A small business named Widgets, Inc. has hired you to evaluate their wireless network security practices. As you analyze their f
    13·1 answer
  • Which of the following is true about stateless applications?
    9·1 answer
  • A numeric literal that is written with a decimal point is called a ________. real number floating-point value decimal literal do
    6·1 answer
  • What does a computer monitor look like when struck really hard?
    15·1 answer
  • Some operating systems add the command interpreter to the kernel .what will be the justification for this design principle?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!