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
The process known as AAA (or “triple A”) security involves three components. _____________ means ensuring that an authenticated
kirill115 [55]

Answer:

The process known as AAA (or “triple A”) security involves three components. Authorization means ensuring that an authenticated user is allowed to perform the requested action.

7 0
4 years ago
6 + 7 = 7 + 6 is an example of which property of addition?
Sauron [17]

Answer:

commutative

Explanation:

The commutative property states that the numbers on which we operate can be moved or swapped from their position without making any difference to the answer.

8 0
3 years ago
Read 2 more answers
Which of the following is a function of an audio programmer?
olchik [2.2K]

Answer:function of audio programmer

1. The audio programmer at a game development studio works under to integrate sound into the game and write code to manipulate and trigger audio cues like sound effects and background music.

6 0
4 years ago
Choose the word that matches each definition. <br> 1 - ISP <br> 2 - HTTP<br> 3 -URL
Sever21 [200]

Answer:

1 - Internet Service Provider

2 - Hypertext Transfer Protocol

3 - Uniform Resource Locator

Explanation:

6 0
3 years ago
A Class B network needs to be subnetted such that it supports 100 subnets and 100 hosts/ subnet. Which of the following answers
zmey [24]

Answer:

The answer to this question is option "B".

Explanation:

In the given question options B and C are correct because class B uses a network, subnet, and host bits that must be equal to the sum of 32 bits. In both options the total bits are equal to 32 bits, a class needs 7 subnet bits at any rate for supports 100 subnets. and other options are not correct that can be defined as:

  • In option, a network, subnet and host bits are not equal to 32 bit because class needs 32 bits. that's why it is wrong.
  • In option, d network bits are 8 it is incorrect because query tells a Class B is a network that uses the number of network bits is equal to 16 bits.

7 0
3 years ago
Other questions:
  • Which of the following savings vehicles usually requires a high minimum balance
    14·1 answer
  • Add a throw statement to the processNumbers function that throws the message "All elements in the list should be numbers." if on
    12·1 answer
  • Which dialog box opens after selecting a cell in the list of prepared data, clicking the insert tab on ribbon and the clicking t
    6·1 answer
  • On net, is technology good or bad for society? Please explain, support your argument, I’ll mark brainliest
    9·2 answers
  • 1. Some of the music in the 1960s was used to protest social and political issues. Is music still used as a form of protest? Why
    13·1 answer
  • Omar is preparing to deliver a presentation to his class. It is about a program to collect samples from an asteroid that has bee
    13·1 answer
  • which statement describe “Hackers”? | A. all have the same motive | B. break into other people’s computers | C. may legally brea
    14·1 answer
  • What are some of the functions in the Consolidate dialog box? Check all that apply.
    6·1 answer
  • with the aid of your own example explain how memory,registers and secondary storage all work together​
    8·1 answer
  • What are the two major types of sas steps?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!