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.
Answers: 1
Computers and Technology, 22.06.2019 00:30
At an open or uncontrolled intersection, yield if a. your road is paved and the crossroad is not b. the cross road is paved and yours is not c. you have two or more passengers in your vehicle d. you did not yield in the last intersection
Answers: 1
Computers and Technology, 22.06.2019 03:00
How can i clip a picture to a question on the computer?
Answers: 1
Computers and Technology, 22.06.2019 11:10
Which are not examples of chronic or persistent stress? moving
Answers: 1
Computers and Technology, 22.06.2019 16:20
Octothorpe is another name for what common computer keyboard symbol?
Answers: 1
Java - using a method, how do i "write a program whose input is a character and a string, and whose...
Computers and Technology, 19.07.2019 05:20
Mathematics, 19.07.2019 05:20
Mathematics, 19.07.2019 05:20
Biology, 19.07.2019 05:20
Mathematics, 19.07.2019 05:20
Mathematics, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Mathematics, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20
Computers and Technology, 19.07.2019 05:20