Computers and Technology
Computers and Technology, 02.12.2019 07:31, puppy5209

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.(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.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 14:00, savannnab1890
Select the correct answer. andre was recently hired by an organization to check for system vulnerabilities. he is supposed to exploit these vulnerabilities and create a report on the extent of damage to which the system was susceptible. what position does andre hold in this organization? a. information security analyst b. information assurance manager c. penetration tester d. network security engineer e. chief information security officer
Answers: 2
image
Computers and Technology, 23.06.2019 17:00, taytay1828
What are the 12 colors of the spectrum called?
Answers: 1
image
Computers and Technology, 23.06.2019 21:10, jmolina57
Asample of 200 rom computer chips was selected on each of 30 consecutive days, and the number of nonconforming chips on each day was as follows: 8, 19, 27, 17, 38, 18, 4, 27, 9, 22, 30, 17, 14, 23, 15, 14, 12, 20, 13, 18, 14, 20, 9, 27, 30, 13, 10, 19, 12, 26. construct a p chart and examine it for any out-of-control points. (round your answers to four decimal places.)
Answers: 2
image
Computers and Technology, 24.06.2019 11:20, davionb556
William travels a lot on business purpose. he needs to regularly communicate with his business partner. he also needs to send out weekly reports to his boss while he is traveling. which web-based application best suits william’s needs? (social media, webmail, wiki) is the best web-based application for william. he can access this application via the internet using a (digital cable, fax machine, web browser).
Answers: 1
Do you know the correct answer?
Java - using a method, how do i "write a program whose input is a character and a string, and whose...

Questions in other subjects: