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
10.A chlorine ion (Cl-) would most likely bond with _____.<br><br> A.Cl-<br> B.Mg<br> C.K+<br> D.O
andrezito [222]
B. Mg
Hope this helps ☺
6 0
3 years ago
Susan is troubleshooting a problem with a computer's network cabling. At which layer of the Open Systems Interconnection (OSI) R
Alisiya [41]

Answer:

Physical layer

Explanation:

The physical layer is responsible for the physical cable or wireless connection.

6 0
3 years ago
Which tab would you click if you didn’t want to use the dialog box launcher in order to change a message’s delivery settings?
atroni [7]
I think the answer is b

6 0
3 years ago
Read 2 more answers
Read two numbers on the keyboard. Display for each: how many digits it consists of, which is the sum of the digits, and which of
Fantom [35]

Answer:

Here it is

Explanation:

#include <iostream>

using namespace std;

int main()

{

   int a, b;

   cin >> a >> b;

   int nr_digits1 = 0, nr_digits2 = 0;

   int sum1 = 0, sum2 = 0;

   int max_digit1 = 0, max_digit2 = 0;

   while (a > 1)

   {

       int digit = a % 10;

       nr_digits1 += 1;

       sum1 += digit;

       if (digit > max_digit1)

       {

           max_digit1 = digit;

       }

       a /= 10;

   }

   while (b > 1)

   {

       int digit = b % 10;

       nr_digits2 += 1;

       sum2 += digit;

       if (digit > max_digit2)

       {

           max_digit2 = digit;

       }

       b /= 10;

   }

   

   cout << "For a: \n" << "   No. of digits: " << nr_digits1 << "\n";

   cout << "   Sum of digits: " << sum1 << "\n";

   cout << "   Max digit: " << max_digit1 << "\n";

   cout << "\n";

   cout << "For b: \n" << "   No. of digits: " << nr_digits2 << "\n";

   cout << "   Sum of digits: " << sum2 << "\n";

   cout << "   Max digit: " << max_digit2 << "\n";

   return 0;

}

6 0
3 years ago
Fill in the blank
Anon25 [30]

Project Management  overview or an  An activity list is the overall work in a project, including, a list of everything that will be delivered to the client.

<h3 /><h3>What is an activity list?</h3>

An activity list is known to be a kind of document that is made up of all the scheduled activities that are said to be down in a project.

Note that all activity includes one or a lot of tasks that, once completed and others.

Since option is not given, answer will be subjective. Project Management  overview or an  An activity list is the overall work in a project, including, a list of everything that will be delivered to the client.

Learn more about project from

brainly.com/question/25009327

#SPJ1

7 0
2 years ago
Other questions:
  • What economic measure is at the highest level since the Great Depression?
    12·1 answer
  • A. True
    7·1 answer
  • Why are coders using encoder software? What are their advantages and disadvantages? And when might a coder need to use the codin
    12·1 answer
  • What are the advantages of using the internet as theinfrastructure for electronic commerce and electronicbusiness?
    6·1 answer
  • The letters a, e, i, o and u are the only vowels. Write a function named vowelUseDict() takes a string t as a parameter and comp
    7·1 answer
  • Which two statements are true about algorithms?
    15·2 answers
  • Select the correct answer from the drop-down menu.
    15·2 answers
  • Long-term memory used by the computer:
    8·2 answers
  • If person A creates an image with a creative common license. Person B then uses the image on his website. Who own the image and
    7·1 answer
  • Which of the following lines of code would reduce the player’s gold by 100 coins?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!