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]
2 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]2 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
The major result of treating 1-butyne with 6M aqueous NaOH would be:_______.A. the production of an alkene.B. the production of
andriy [413]

Answer:

D. nothing, as the alkyne would not react to an appreciable extent.

Explanation:

Nothing, as the alkyne would not react to an appreciable extent.

6 0
1 year ago
In database software, a record is a
Rzqust [24]

Answer:

In database software a record is a group of related data held within the same structure.

4 0
2 years ago
Consider a disk that rotates at 3600 rpm. The seek time to move the head between adjacent tracks is 2 ms. There are 32 sectors p
jasenka [17]

Answer:

19.71 ms

Explanation:

The disk rotates at 3600 rpm, hence the time for one revolution = 60 / 3600 rpm = 16.67 ms.

Hence time to read or write on a sector = time for one revolution / number of sectors per track = 16.67 ms / 32 sectors = 0.52 ms

Head movement time from track 8 to track  9 = seek time = 2 ms

rotation time to head up sector 1 on track 8 to sector 1 on track 9 = 16.67 * 31/32 = 16.15 ms

The total time = sector read time +head movement time + rotational delay + sector write time = 0.52 ms + 2 ms + 16.15 ms + 0.52 ms = 19.19 ms

3 0
2 years ago
Each frame is composed of a number of colors recorded in digital format; we call these pixels. What information does the number
Nookie1986 [14]
I'd say the size of the frame.

The size, quantity and color combination of pixels is measured in terms of display resolution. A resolution, however, is the number of pixels in an image and is identified by the width and the height. How you’ve set the resolution for the display screen will determine the specific size of the pixels.






7 0
2 years ago
Write a statement to add the key Tesla with value USA to car_makers. Modify the car maker of Fiat to Italy. Sample output for th
marishachu [46]

Answer:

Input code:

car_makers = {'Honda': 'Japan', 'Fiat': 'Germany'}

#add Tesla and USA as corresponding value

car_makers['Tesla'] = 'USA'

#change Fiat entry to Italy instead of Germany

car_makers['Fiat'] = 'Italy'

print(car_makers)

print('Honda made in', car_makers['Honda'])

print('Fiat made in', car_makers['Fiat'])

print('Tesla made in', car_makers['Tesla'])

Explanation:

The first line is a define object in the python code, containing two entries of Honda and Fiat and their respective countries.

The python code adds an entry to the object "car maker" using the bracket notation, the tesla car from USA.

The country of the Fiat car is changed from Germany to Italy, using the bracket notation.

The output of the complete object and the individual cars is given.

<u>output of the python code:</u>

{'Honda': 'Japan', 'Fiat': 'Italy', 'Tesla': 'USA'}

Honda made in Japan

Fiat made in Italy

Tesla made in USA.

7 0
2 years ago
Other questions:
  • Which selections are possible for controlling the start time of audio playback? Check all that apply. Automatic Rewind when done
    10·1 answer
  • Which key retains its uniqueness even after you remove some of the fields?
    14·1 answer
  • 9.10: Reverse ArrayWrite a function that accepts an int array and the array ’s size as arguments . The function should create a
    9·1 answer
  • What company built its first computer from a wooden box
    12·2 answers
  • A small company is moving towards sharing printers to reduce the number of printers used within the company. The technician has
    14·1 answer
  • Given three dictionaries, associated with the variables, canadian_capitals, mexican_capitals, and us_capitals, that map province
    11·1 answer
  • "Suppose there is a class Alarm. Alarm has two class variables, code which contains a String value representing the code that de
    10·1 answer
  • Joe, Kate and Jody are members of the same family. Kate is 5 years older than Joe. Jody is 6 years older than Kate . The sum of
    11·2 answers
  • Write an expression to print each price in stock prices.
    15·1 answer
  • When authenticating a user's password, the password supplied by the user is authenticated by comparing the ____ of the password
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!