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, 22.06.2019 10:40, pbarbee3034
Nims is applicable to all stakeholders with incident related responsibilities. true or false
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, Janznznz1121
Your computer running windows 10 is doing some very strange things with the operating system. you are fairly certain it is not a hardware issue. you need to try to get further insight into what is going on within the operating system. which tool would be best suited for this?
Answers: 2
image
Computers and Technology, 22.06.2019 18:30, Akkenson17871
The "instance" relationship shows that something is an object of a
Answers: 1
image
Computers and Technology, 23.06.2019 20:00, emmaraeschool
Me ajude por favor , coloquei uma senha e não consigo tira-la no chorme
Answers: 2
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:

Konu
History, 21.05.2020 21:10