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 day 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 [849]1 day 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
Which of the following is an absolute cell reference
Amiraneli [962]
The term for the contents of the cell is an absolute cell reference. Excel allows each cell to contain numbers, strings, or formulas. Users can enter values into a cell and apply built-in formulas to perform calculations and obtain results in the target cell. When users attempt to copy and paste data into another cell, they can use the paste special option to select values, meaning that only the data is copied, excluding the formula; this is known as the absolute reference of the cell. With paste special, users can also replicate images or Unicode.
6 0
23 days ago
Flight Simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of the followi
Natasha_Volkova [946]

Answer:

C) Flight Simulation software offers pilots a more authentic training experience compared to actual flight sessions.

Explanation:

Flight simulation programs are utilized to instruct future pilots in aviation schools. They replicate the circumstances that pilots will likely encounter during real flights and how to manage them.

This software enables pilots to rehearse landings across various types of landscapes and weather conditions without geographical limitations.

Additionally, it is cost-effective by reducing expenses on fuel and maintenance related to actual training flights.

Nevertheless, it does not engage pilots in a more authentic experience than actual training flights.

7 0
1 month ago
Read 2 more answers
How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).
Rzqust [962]

Answer:

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

if num1 < 1 or num2<1:

     print("Input must be greater than 1")

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

Explanation

The next two lines prompt the user for two numbers

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

The next if statement checks whether either or both inputs are not positive

if num1 < 1 or num2<1:

     print("Input must be greater than 1")-> If true, this print statement will run

If the conditions are not met, the program prints the quotient and remainder

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

3 0
28 days ago
Heather’s computer display is having a problem in which the desktop seems to be shifting. She has sent you a picture of the prob
Rzqust [962]
The likely cause of the issue with Heather's display is that the video cable is not seated correctly. Explanation: The details provided point to the possibility that a misaligned video cable may cause the desktop to appear to shift, which aligns with symptoms such as frequent screen flickering or a blank display. While it’s plausible for the GPU on the video card to be overheating, that generally results in visual artifacts rather than the specific shifting behavior described.
7 0
17 days ago
Julio is trying to decide between 4 different vendors for a new IT system. Vendor A is less expensive than Vendor C. Vendor C is
amid [867]

Answer:

Vendor B

Explanation:

By using letters to signify each vendor and the symbol < to indicate which is cheaper, the problem can be summarized as follows: A<C, B<C, B<D, D<A.

These inequalities show that the vendors on the left are less expensive than those on the right, therefore, any vendor appearing on the right in these expressions cannot be the cheapest, ruling out C, D, and A. Thus, the least expensive vendor is B.

8 0
1 month ago
Other questions:
  • In the Scrum board, prioritizing the issue backlog is done in the ———- mode.
    7·1 answer
  • In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
    8·1 answer
  • Sushant is a new manager and he wants to share his ideas and working protocol with his team.Compare the advantages and disadvant
    13·1 answer
  • Two middle-order batsmen are compared based on their performance in their previous cricket match.
    7·1 answer
  • Until 2015, each new Roblox user automatically had one friend. What was he called?
    12·2 answers
  • Modern operating systems decouple a process address space from the machine’s physical memory. List two advantages of this design
    15·1 answer
  • Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per li
    11·1 answer
  • You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
    12·1 answer
  • Given main(), define the Team class (in file Team.java). For class method getWinPercentage(), the formula is:teamWins / (teamWin
    15·1 answer
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!