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
Stolb23 [73]
4 years ago
12

Write a recursive method that finds the number of occurrences of a specified letter in a string using the following method heade

r: public static int count(String str, char a) For example, count("welcome",' e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the string.
Computers and Technology
1 answer:
Dafna1 [17]4 years ago
3 0

Answer:

//Java program to find the number of occurrences of a specified character in a string.

// Import the required packages.

import java.io.*;

import java.util.*;

//class declaration

class CharacterCount

{

// Main method.

public static void main (string args[ ] )

{

  try

      {

     // Taking the input from the user.

         System. out.print ("Type a string to analyze: ");

     // Creating the scanner class object.

         scanner input = new scanner (system. in);

         String str = input .next();

         System.out.print("Type a character to check: ")

         String temp = input.next();

         char c = temp.charAt(0);

     // Calling the method to get the character count.

         int count = <em>count</em>(str,c);

     // Displaying the result.

         system.out.print In("There are " + count + " " + c + " 's. ");

     // catching the exception.

         catch(Exception e)

         System.out.print In("Exception has occured in the class . Program will exit. ");

      // Exiting the system.

         System.exit(0);

         }

}

// Method to calculate the character count.

public static int count(String str, char a)

  {

    // checking for null string input.

      if(str.equals(""))

      {

       return 0;

      }

      else

      {

      int k = 0;

    // Character matching check.

      if ( str.substring(0, 1) . equals (Character.<em>toString</em>(a)) )

      {

   // Incrementing the counter.

      k++;

      }

   // Recursive call

      k += <em>count</em>(str.substring(1) , a);

              return k;

       }

     }

}

Explanation:

Output should show: Type a string to analyze: welcome

                                   Type a character to check: e

                                   There are 2 e's.

You might be interested in
A communications objective is
Kazeer [188]

Answer:

They are used to identify your audience, craft messages and evaluate results. Communication Objectives are - as the name suggests – the process of setting targets for communication.Changing company or brand perceptions is another common communication objective.

Hope this helps! If so please mark brainliest and rate/heart to help my account

8 0
4 years ago
Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
olga_2 [115]

Answer:

usatestprep literally just does what the name says; it prepares you for tests in america. it doesn't kick you off if you access other windows

Explanation:

3 0
4 years ago
The questions are in the pictures, i basically have to create a web page, drop the html code and files below thank you.
matrenka [14]

This contains pretty much what you need:


<!DOCTYPE html>



<html>


<head>


   <meta charset="utf-8" />


   <title>The Page Title</title>


</head>


<body>



   <h1>First paragraph</h1>


   <p>This is a paragraph of text.</p>


   <h2>Second level paragraph</h2>


   <p>


       Here is an unordered list of options:


       <ul>


           <li>First</li>


           <li>Second</li>


           <li>Third</li>


       </ul>


       Here is another unordered list of options:


       <ul>


           <li>First</li>


           <li>Second</li>


           <li>Third</li>


       </ul>


       Here is an ordered list of options:


       <ol>


           <li>First</li>


           <li>Second</li>


           <li>Third</li>


       </ol>


   </p>


   <h4>Third level</h4>



</body>


</html>

3 0
3 years ago
Suppose a program written in language L1 must be executed on a machine running a program running in language L0. What important
Whitepunk [10]

Question Completion with Options:

a. Translation of the entire L1 program into L0 code

b. Translation of the L0 program into L1 code

c. Creation of a language L3 that interprets L0 instructions

d. Interpretation of each L1 statement using L0 code as the L1 program is running.

Answer:

The important operations that must take place in this scenario are:

a. Translation of the entire L1 program into L0 code

d. Interpretation of each L1 statement using L0 code as the L1 program is running.

Explanation:

Translation enables decoding to take place.  This means that the L1 program is decoded into a language that the L0 program can understand and execute.  Without this translation, the higher level language of L1 will not be understood by the machine language of the L0 programs.  Translation of a code creates a shared understanding, thereby easing program execution.  Code translation is simultaneously accompanied by interpretation.

8 0
3 years ago
Complete each sentence to describe features of the VLOOKUP function. The VLOOKUP function structure begins with =VLOOKUP( , …) T
fenix001 [56]

Answer:

The complete sentences are:

<em>The VLOOKUP function structure begins with =VLOOKUP(value, table, col_index, [range_lookup])</em>

<em>To use the VLOOKUP function, the lookup value should be in the first column of the table.</em>

<em></em>

Explanation:

Required

Complete the given sentence with the right values

In Excel, the syntax of the VLOOK function is:

<em>=VLOOKUP (value, table, col_index, [range_lookup])</em>

value -> The value to look up to and it should be located in the first column of the table

table -> The table name

col_index -> The column number to check

[range_lookup] -> This is optional and it returns either true of false depending on the result of the query,

6 0
3 years ago
Other questions:
  • Which sentence best describes an activity stream?
    10·2 answers
  • a problem exists when the current condition differs from a desired condition. This idea defines which step in problem-solving?
    13·2 answers
  • Assume that scotus is a two-dimensional character array that stores the family names (last names ) of the nine justices on the S
    6·1 answer
  • Write a program to read customer number, Name, loan amount, interest rate and time of repayment. Calculate and display the EMI .
    9·1 answer
  • Which of the following statements about certificates is true?
    14·2 answers
  • What effect does the interconnectedness of modern media have on society?
    14·2 answers
  • 4. Explain the term prejudice. What is an example of prejudice as it relates to parenting?
    11·1 answer
  • tls Explain in your own words how, by applying both asymmetric and symmetric encryption, your browser uses TLS to protect the pr
    8·1 answer
  • Describe how pseudocode makes programming more efficient for large programming tasks.
    10·2 answers
  • What type of movement does the output produce
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!