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
ki77a [65]
3 years ago
7

Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in

the string.
Ex: If the input is: n Monday,
the output is: 1
Ex: If the input is: z Today is Monday,
the output is: 0
Ex: If the input is: n It's a sunny day,
the output is: 2
Case matters. n is different than N.
Ex: If the input is: n Nobody,
the output is: 0

Your program must define and call the following function that returns the number of times the input character appears in the input string.

int CountCharacters(char userChar, string userString)
Computers and Technology
1 answer:
Sladkaya [172]3 years ago
4 0

Answer:

The program written in Java is given in the explanation section

Explanation:

public class num9 {

//Defining the method CountCharacters()

   public static int CountCharacters(char userChar, String userString){

       int c = userString.length();

       int count=0;

       for(int i=0; i<c; i++){

           if(userString.charAt(i)==userChar){

               count++;

           }

       }

       return count;

   }

//Main method begins here

   public static void main(String[] args) {

   char n ='n';

   String word = "Monday";

//Calling the method CountCharacters()

       System.out.println(CountCharacters(n,word));

   }

}

You might be interested in
17) you need to locate an article that (1) is published by a university or proffessional association(2) is authored by clearly d
mestny [16]
Scholarly article. [email protected]
3 0
4 years ago
What is incorrect about the following code? Suggest a possible revision of the code to correct the error.
Ad libitum [116K]
This is really cool but no one cares
5 0
3 years ago
If you are installing separate anti-virus and anti-spyware programs, which should you install first
Vera_Pavlovna [14]
Probably the anti virus, so you don't get a virus from downloading the anti spyware program.
6 0
3 years ago
your browsing the internet and realize your browser is not responding. which of the following will allow you to immediately exit
Mandarinka [93]

Answer:

Task Manager is the answer

8 0
4 years ago
What cell address indicates the intersection of the first row and the first column in a worksheet?
Roman55 [17]
The answer is A1. 

The columns are arranged alphabetically, and the rows are ordered numerically. The cell address states the column, a letter, followed by the row, a number. The first cell address, the top-left cell of the sheet, is A1
7 0
3 years ago
Read 2 more answers
Other questions:
  • In the process of benchmarking for a variable expense (such as payroll) the typical metrics used are "Total Dollars" and "Dollar
    8·1 answer
  • The Cisco IOS automatically modifies the dead interval when the _____ interval is changed. (Points : 2) hello
    13·1 answer
  • The speed of sound depends on the material the sound is passing through. Below is the approximate speed of sound (in feet per se
    9·1 answer
  • How read binary file in c++
    7·1 answer
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • I need someone to help. This is the links I found and I'm going through the same thing. I live in small town where they think I'
    14·1 answer
  • Yolanda first breaks down the whole game she needs to program into modules. She then breaks these modules into smaller modules u
    11·1 answer
  • Which of the following languages does not provide built-in-pattern matching operations (the language, although, has pattern matc
    14·1 answer
  • In the code snippet, what is the “win” part called in programming?
    12·1 answer
  • Complete the sentence about bias and equity.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!