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
Wewaii [24]
3 years ago
8

Java - Using a method, how do I "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. Your program must define and call the following method that returns the number of times the input character appears in the input string.
public static int countCharacters(char userChar, String userString)"

So far I have the following:
import java.util.Scanner;

public class LabProgram {

public static int countCharacters(char userChar, String userString)
{
// Create an object of the Scanner class to allow for user inputs
Scanner input = new Scanner(System.in);

// Store text in a variable
userString = input.nextLine();

// Store character in a char variable
userChar = 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 < userString.length(); i++) {
if (userString.charAt(i) == userChar) {
count++;
}

}

// Print out the number of occurrences due to count
System.out.println(userChar + " appears this many times " + count);
}

public static void main(String[] args) {
countCharacters(userChar, userString);
}

}
and my error is that I can't get it to run on main / I don't know where everything goes. I found the code somewhere and I've tried modifying it.
Computers and Technology
1 answer:
Ksju [112]3 years ago
6 0

Answer:Java - Using a method, how do I "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. Y"

Explanation:

You might be interested in
You're browsing the Internet and realize your browser is not responding. Which of the following will allow you to immediately ex
Korolek [52]
You can forcibly close any program with task manager.
5 0
3 years ago
Read 2 more answers
Award documentation is typically required to be prepared and submitted within how long after the end of a project period:_____.
Stella [2.4K]

Award documentation is typically required to be prepared and submitted within how long after the end of a project period of 90 days.

What does Award includes?

  • Awards to international organizations and government institutions, whether or whether they are covered by SNAP, must include annual expenditure information.
  • The report shall be submitted for each budget period, if necessary on an annual basis, no later than 90 days following the end of the calendar quarter in which the budget period concluded.
  • The report must include information on any allowed extensions to the budgetary period. If more regular reporting is necessary, both the frequency and the deadline shall be stated in the NoA.

Learn more about the Post-Award Monitoring and Reporting with the help of the given link:

brainly.com/question/15415195

#SPJ4

5 0
1 year ago
Juan wrote a loop to print all the prime numbers between 1 and 100. But instead of stopping at 100, it continues on and on forev
aniked [119]

Answer:

oh im cool

Explanation:

6 0
2 years ago
Technician A says that a lead acid battery uses straight Hydrochloric acid for electrolyte. Technician B says that a lead acid b
konstantin123 [22]

Technician B is correct

It is safe to say that Lead acid uses sulfuric acid. When fully charged, the electrolyte consist of 40% concentrated sulfuric acid and the remainder consist of mostly water. However, as it discharges, both the positive and the negative plates turn into lead sulfate with the electrolyte loosing much of its dissolved sulfuric acid and water.

7 0
3 years ago
Read 2 more answers
(True or False) The speed at which data travels on a bus is referred to as the word size.
geniusboy [140]

Answer:

True

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • A password checking system that disallows user passwords that are proper names or words that are normally included in a dictiona
    15·1 answer
  • Vaporization is the process in which liquid is sufficiently cooled to change states of matter from a liquid to a vapor true or f
    8·1 answer
  • Do AirPods Pro have a green flashing light when charging?
    11·2 answers
  • A technician wants to limit access to a group of folders and is using Group Policy to prevent the users in the sales department
    9·1 answer
  • At which track meet did two runners finish in a time equivalent to the mode?
    14·1 answer
  • Why is it important to isolate evidence-containing devices from the internet?
    11·1 answer
  • In Subtractive empathy, the counselor responses gives back less (or distorts) than what the client has said. slightly add someth
    14·1 answer
  • 1. Why does a computer have different types of ports?
    14·2 answers
  • What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer
    8·1 answer
  • each data mining technique has its advantages and limitations. which data mining technique mimics the neural structure of the br
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!