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]
1 year 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]1 year 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
2 Name the package that contains scanner class?​
Marat540 [252]
the answer is Java.util.scanner
5 0
1 year ago
Assume that month is an int variable whose value is 1 or 2 or 3 or 5 ... or 11 or 12. Write an expression whose value is "jan" o
Tamiku [17]

Answer:

The code is given below

Explanation:

The correct syntax would be to place appropriate parenthesis.

(month==1?"jan":(month==2?"feb":(month==3?"mar":(month==4?"apr":(month==5?"may":(month==6?"jun":(month==7?"jul":(month==8?"aug":(month==9?"sep":(month==10?"oct":(month==11?"nov":"dec")))))))))));

Similarly, you can also use the following code:

String[] months = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };

int month = 1;

String monthDescription = months[month - 1];

7 0
2 years ago
Brittany just pulled up a database table with employee information that contains 50 records of employees at her company. Which o
lesantik [10]

Answer:

The answer is: Operations.

Explanation:

A database operation accesses to information of a relational database. In this case, Brittany has creates the database operation that select employee information of her company and the database has returned a result set. The SQL statement to perform operations on a database are:

  • INSERT
  • SELECT
  • UPDATE
  • DELETE

3 0
2 years ago
Two middle-order batsmen are compared based on their performance in their previous cricket match.
Zolol [24]
How many points is this for
5 0
2 years ago
Rebooting a system in an attempt to fix a problem is an example of the ____ problem-solving strategy.
expeople1 [14]
Software trouble shooting
4 0
2 years ago
Other questions:
  • Which of the following is true with regard to defensive programming? Preconditions should never be visible to callers. Program c
    8·1 answer
  • A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
    6·1 answer
  • Write a loop that counts the number of space characters in a string. Recall that the space character is represented as ' '.
    11·1 answer
  • While creating an animation, Gina has prepared a document stating the purpose and type of audience for the animation. What has
    6·1 answer
  • We have an internal webserver, used only for testing purposes, at IP address 5.6.7.8 on our internal corporate network. The pack
    15·1 answer
  • Which are types of lines? Choose three answers.
    9·1 answer
  • Nstructions
    7·1 answer
  • Write code which takes a sentence as an input from the user and then prints the length of the first word in that sentence.
    6·1 answer
  • Chinh wants to have a program print, "Sorry, but that isn’t one of your options" until the user enters the correct information.
    13·1 answer
  • Write a function named shout. The function should accept a string argument and display it in uppercase with an exclamation mark
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!