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
Which of the following statements is not true? Question 16 options: a) SQL is the most popular query language used for interacti
lisov135 [29]

Answer:

The answer to this question is option "d".

Explanation:

In this question option d (A user fills out a form to construct a description of the data desired in a SQL search) is not true. Because SQL stands for Structured Query Language. This is a query language used to communicate with a database and a user fills the form. Which is not possible in the SQL. So the option d is not true.

4 0
3 years ago
Which type of network allows backups and network security to be centrally located?
BlackZzzverrR [31]

Answer:

B

Explanation:

B is the answer.

3 0
2 years ago
What's the name of the file mainly used to save power point
son4ous [18]
.PPT is the extention for the files downloaded from Powerpoint.
7 0
3 years ago
Read 2 more answers
_____ of a global information system (GIS) concentrates on medium-range activities that move an organization toward achieving lo
Dafna11 [192]

Answer: (A) Tactical support

Explanation:

 GIS is the global information system in which the data is delivered worldwide in the form of information system. The global information system achieve long term goals in an organization.

  • The tactical support is used in the global information system for concentrating the activities on the medium range in an organization.  
  • The tactical support is one of the effective way to producing the desirable result and also achieve the main strategic objective.

Therefore, Option (A) is correct.

8 0
3 years ago
Which of the following clauses will stop the loop when the value in the intPopulation variable is less than the number 5000?
garik1379 [7]

Answer:All of the above

Explanation:

4 0
1 year ago
Other questions:
  • Suggest how the following requirements might be rewritten in a quantitative way. You may use any metrics you like to express the
    7·1 answer
  • Technician A says copper has a low resistance. Technician B says the length of wire doesn't affect resistance. Who is correct?
    11·1 answer
  • What does this say:<br> √ans
    6·2 answers
  • When you select Insert and click on a shape the mouse pointer turns into a/an
    12·2 answers
  • Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
    10·1 answer
  • A company's desire to sell products and services: A. will ultimately lead to its doom. B. explains why the web took off C. can d
    9·2 answers
  • The D:\ drive in your computer has been formatted with NTFS. The Mary user account has been assigned the following permissions:
    10·1 answer
  • The advancement of technology in our daily lives has changed how we interact with the world.
    10·1 answer
  • Here’s my last question
    12·2 answers
  • Some operating systems add the command interpreter to the kernel .what will be the justification for this design principle?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!