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
HELP 11 pointsw to the person who helps me
baherus [9]
I believe it Is 2 and 3
7 0
4 years ago
Read 2 more answers
Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
attashe74 [19]

Answer:

Let me see the picture clearly

Explanation:

5 0
4 years ago
Wight an essay on Knowledge sharing among robots.<br> please and please do not delete my question.
PolarNik [594]

Answer:

Writing an essay to robots is very bad. The robots could steal your information and essay. Never share essays with robots.

Explanation:

5 0
2 years ago
(4 points.) Write an algorithm (i.e., step-by-step instructions) via which someone could walk or drive from some origin to some
Elis [28]

Answer:

The algorithm is as follows :

1. Record Current Position, Final Destination

2. While Current Position is not Final Destination, repeat the following:

2.1 If destination location is up then:

  2.1.1 If an obstacle is directly above you then:

     2.1.1.1 Look for alternate position (left, right, down)

     2.1.1.2 If alternate position is found then

        2.1.1.2.1 Move there

        2.1.1.2.2 Record Current Position

     2.1.1.3 If no alternate position is found then

        2.1.1.3.1 Call for help

        2.1.1.3.2 End

  2.1.2 If no obstacle is directly above you then:

     2.1.2.1 Move up

     2.1.2.1 Record Current Position

2.2 If destination location is down then:

  2.2.1 If an obstacle is directly below you then:

     2.2.1.1 Look for alternate position (left, right, up)

     2.2.1.2 If alternate position is found then

        2.1.1.2.1 Move there

        2.2.1.2.2 Record Current Position

     2.2.1.3 If no alternate position is found then

        2.2.1.3.1 Call for help

        2.2.1.3.2 End

  2.2.2 If no obstacle is directly below you then:

     2.2.2.1 Move down

     2.1.2.1 Record Current Position

2.3 If destination location is right then:

  2.3.1 If an obstacle is directly by your right then:

     2.3.1.1 Look for alternate position (down, up, left)

     2.3.1.2 If alternate position is found then

        2.3.1.2.1 Move there

        2.3.1.2.2 Record Current Position

     2.3.1.3 If no alternate position is found then

        2.3.1.3.1 Call for help

        2.3.1.3.2 End

  2.3.2 If no obstacle is directly by your right then:

     2.3.2.1 Move right

     2.3.2.1 Record Current Position

2.4 If destination location is left then:

  2.4.1 If an obstacle is directly by your left then:

     2.4.1.1 Look for alternate position (down, up, right)

     2.4.1.2 If alternate position is found then

        2.4.1.2.1 Move there

        2.4.1.2.2 Record Current Position

     2.4.1.3 If no alternate position is found then

        2.4.1.3.1 Call for help

        2.4.1.3.2 End

  2.4.2 If no obstacle is directly by your left then:

     2.4.2.1 Move left

     2.4.2.1 Record Current Position

Explanation:

<em>The algorithm is straight forward.</em>

<em>All it does is to check for available position and move into the position if there is any available.</em>

<em>It keeps checking and moving until an obstacle prevents it from moving.</em>

5 0
3 years ago
Tools used in a particular career depend on the tasks performed. True or false
Aliun [14]
True so hopefully this will help
8 0
3 years ago
Read 2 more answers
Other questions:
  • JAVA
    5·1 answer
  • What is the absolute pathname of the YUM configuration file? REMEMBER: An absolute pathname begins with a forward slash
    12·1 answer
  • Which of the following is the java comparison operator for "not equal to"
    10·1 answer
  • Is rhis app plagerism free
    11·1 answer
  • Charlie does not think he will be able to finish this project by the deadline at this point in the decision making process to so
    8·1 answer
  • List four useful spreadsheet functions and explain what they do.
    11·1 answer
  • Write a compound inequality that is represented by the graph.
    14·1 answer
  • Write a complete method from the client perspective that duplicates each element in place in a ListInterface object. For example
    8·1 answer
  • Meenakshi has created a presentation of six slides. The slides have the same background, but s wants to change the background of
    15·1 answer
  • Ingredient Adjuster
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!