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
Jeremy Bridges is an executive for Green Web Designs, where his primary role is to ensure the security of business systems and d
klasskru [66]

Answer:

Chief Security Officer

Explanation:

According to the given statement in the question the Jeremy's role in the company is "Chief Security Officer (CSO)".

The chief Security officer has the role of developing and looking on to the strategies and policies that are required for maintaining the operational, strategic, financial and reputational security  of the  overall company.

6 0
3 years ago
A page-replacement algorithm should minimize the number of page faults. We can achieve this minimization by distributing heavily
tekilochka [14]

Answer:If you think that a blank sheet of paper or a blinking cursor on the computer screen is a scary sight, you are not alone. Many writers, students, and employees find that beginning to write can be intimidating. When faced with a blank page, however, experienced writers remind themselves that writing, like other everyday activities, is a process. Every process, from writing to cooking to bike riding to learning to use a new cell phone will get significantly easier with practice.

Just as you need a recipe, ingredients, and proper tools to cook a delicious meal, you also need a plan, resources, and adequate time to create a good written composition. In other words, writing is a process that requires steps and strategies to accomplish your goals.

These are the five steps in the writing process:

Prewriting

Outlining the structure of ideas

Writing a rough draft

Revising

Editing

Effective writing can be simply described as good ideas that are expressed well and arranged in the proper order. This chapter will give you the chance to work on all these important aspects of writing. Although many more prewriting strategies exist, this chapter covers six: using experience and observations, freewriting, asking questions, brainstorming, mapping, and searching the Internet. Using the strategies in this chapter can help you overcome the fear of the blank page and confidently begin the writing process

Explanation:

4 0
2 years ago
A measure of the twisting or rotational force that an engine can produce is called
Snowcat [4.5K]
The correct answer is torque.

Torque
A twisting force that tends to cause rotation, commonly used term among mechanics and engineers.
7 0
2 years ago
What is considered any computer system that isn't a general-purpose pc or server?
Kay [80]

Embedded system is considered any computer system that isn't a general-purpose pc or server.

<h3>What is an embedded system?</h3>

An embedded system is a combination of computer hardware and software designed for a specific function. Embedded systems may also function within a larger system. The systems can be programmable or have a fixed functionality.

<h3>What is embedded system and its types?</h3>

Embedded systems comprise hardware and software that work together to perform specific tasks. They rely on microprocessors, microcontrollers, memory, input/output communication interfaces, and a power supply to function

To learn more about embedded system, refer

brainly.com/question/13014225

#SPJ4

3 0
2 years ago
What is the difference between the (BIOS) basic.input.output.system and R.O.M
abruzzese [7]
EX: A BIOS is a file used to make an emulator work properly. <span>A ROM is a copy of a game downloadable online.</span>
6 0
3 years ago
Other questions:
  • Bit rate is a measure of how many bits of data are transmitted per second. Compared to videos with a higher bit rate, the same v
    13·1 answer
  • A blank is a link on a web page that leads to another web page.
    14·1 answer
  • LargeCo is planning a new promotion in Alabama (AL) and wants to know about the largest purchases made by customers in that stat
    7·1 answer
  • PowerPoint allows you to input files from variety of sources, such as Microsoft access.
    6·1 answer
  • In fixed-width files, each record is on a separate line and the fields are separated by a special character.
    7·1 answer
  • Which of the following is not true about VOIP?
    9·1 answer
  • You can count on everything online to be 100% accurate. <br> A. FALSE <br> B. TRUE
    11·2 answers
  • Which of the following is not a component of Power BI?
    5·1 answer
  • Write an algorithm to print the odd number from 100 to 1​
    13·1 answer
  • which two statements about incoming and outgoing interfaces in firewall policies are true? (choose two.)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!