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]
3 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]3 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
What is wrong with each of the following?
ankoles [38]

Answer:

The answer to this question is given below in the explanation section

Explanation:

shoNum + shoNum2 = shoTotal

in this code statement,  the order of operation is wrong because the calculation in programming always done at the right side of dependent variables.  so the correct statement of code is

<em> shoTotal = shoNum + shoNum2;</em>

shoNum = 10 * 4

This statement is programmatically correct, because the ShoNum value becomes 40 after performing the multiplication operation on its assigned value  (10 multiply by 4). However, it is noted that the empty space mostly ignored by the compiler. So, the correct is <em>shoNum = 10*4;</em>

Dim decPrice As Decimal = "$4.99"

The dollar sign is appeared in along with its value. So, if you assign value to a decimal variable, you need to assign only digit value (do not mix value with symbol or text) and also do not put quotation marks around value, if you put quotation marks around value then this value will be consider as a text value.

So, the correct statement is :

<em>Dim decPrice As Decimal = 4.99;</em>

shoCube= (shoSide)3

In this statement, cube is calculated of shoSide variable, mathematically it is right, but programmatically it is incorrect. Because, you missed the multiplication operation (*) between the operand shoSide and 3. it should

be as  shoSide raise to power 3.

the correct statement is : shoCube = (shoSide * shoSide *shoSide);

4 0
4 years ago
Tara needs to select all of the text in a Word document. Which keyboard shortcut will achieve this goal?
user100 [1]
Ctrl + a im pretty sure
3 0
4 years ago
Read 2 more answers
You manage a network that uses a single switch. All ports within your building connect through the single switch. In the lobby o
Karo-lina-s [1.5K]

Answer:

<u>VLANs</u>

Explanation:

Virtual LANs (VLANs) are a type of network connection or arrangement of network devices in the same broadcast domain. They are called Virtual LANs because they represent fractions or subgroups in the switch ports found in an Ethernet LAN.

Indeed, because of their topological arrangement, this reduces the security risk of unauthorized access to sensitive data or devices since the host can be placed on a different VLAN. Hence, in this scenario, using this network feature would allow visitors to plug into these ports to gain internet access, but they would not have access to any other devices on the private network.

5 0
3 years ago
Moore’s law refers to?
puteri [66]

Answer:

Moore’s law states that processor speeds, or overall processing power for computers will double every two years.

Explanation:

  • Moore’s law is more than an observation than a law which was originated in 1970. The observation is about the number of transistors that is present in any system or an integrated system that will be doubled every couple of years.
  • The real-world application of Moore's law can be seen during computing your business taxes, piloting a spaceship, or changing the television station, etc.
7 0
3 years ago
What is a data broker?
AleksAgata [21]

Answer:

The correct option is a.

A business that collects personal information about consumers and sells that information to other organizations.

Explanation:

Data brokers, also known as data suppliers, data fetchers, information brokers, or even data providers are businesses or companies (even individuals) that, on the most basic level, source and aggregate data and information (mostly information that are meant to be confidential or that are in the real sense difficult to get) and then resell them to third parties. These third parties could be other data brokers.  

They collect data and information from a wide range of resources and sources - offline and/or online e.g web access history, bank details, credit card information, official records (such as birth and marriage certificates, driver's licenses).  

Brokers can steal round about any information. Examples of information that brokers legally or illegally steal are full name, residential address, marital status, age, gender, national identification number, bank verification number. Brokers and hackers are siblings.

A couple types of data brokers are:

1. Those for fraud detection

2. Those for risk mitigation  

Hope this helps!

6 0
3 years ago
Other questions:
  • Complete the following:_____
    9·1 answer
  • Forensic computer investigators must _____.
    6·2 answers
  • FREE POINTS JUST ANSWER MY LATEST TWO QUESTIONS PLEASE
    10·2 answers
  • What happens when two computers have the same IP address?
    13·1 answer
  • A student opens a recently purchased software package and begins reading the enclosed materials. What information might be inclu
    6·1 answer
  • Computers help eliminate that repetitive of manual task. How can this benefit you in in your overall career
    7·2 answers
  • You're working in a table that has three columns and five rows. Since the first row will be a header row, you want it to span al
    6·1 answer
  • A cycle merchant allows 15% discount on the marked price of a bicycle and still he makes a profit
    14·1 answer
  • This is a human-made physical system.
    15·1 answer
  • Question 1 Which portion of the PuTTY package allows you to perform file transfers using the SCP (Secure Copy) protocol?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!