subject

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.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 17:30, josephvcarter
Who invented the tv .hint it was 2 people
Answers: 1
image
Computers and Technology, 23.06.2019 19:00, Heyitsbrandi
Now you’re on your own. include a short summary of this section with plots in your lab report. write a matlab script file to do steps (a) through (d) below. include a listing of the script file with your report. 1 the soundsc(xx, fs) function requires two arguments: the first one (xx) contains the vector of data to be played, the second argument (fs) is the sampling rate for playing the samples. in addition, soundsc(xx, fs) does automatic scaling and then calls sound(xx, fs) to actually play the signal. mcclellan, schafer, and yoder, dsp first, 2e, isbn 0-13-065562-7. prentice hall, upper saddle river, nj 07458. c 2015 pearson education, inc. 4 mcclellan, schafer and yoder, signal processing first. prentice hall, upper saddle river, new jersey, 2003. c 2003 prentice hall. (a) generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 hz sinusoids defined in the next part, part (b). use a definition for tt similar to part 2.2(d). if we use t to denote the period of the sinusoids, define the starting time of the vector tt to be equal to t , and the ending time as ct . then the two cycles will include t d 0. finally, make sure that you have at least 25 samples per period of the sinusoidal wave. in other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. (b) generate two 4000 hz sinusoids with arbitrary amplitude and time-shift. x1.t / d a1 cos.2
Answers: 1
image
Computers and Technology, 23.06.2019 21:40, minnie7760
Draw the resistor’s voltage and current phasors at t=15ms. draw the vectors with their tails at the origin. the orientation of your vectors will be graded. the exact length of your vectors will not be graded.
Answers: 2
image
Computers and Technology, 24.06.2019 08:50, bo4isbad
Write a program that will compute the volume of ice cream served in a cone. as you can see in the diagram below, the ice cream is served as a hemisphere of frozen deliciousness on top of a cone, which is also packed with frozen deliciousness. thus, the total volume of ice cream sold is the volume of the hemisphere plus the volume of the cone. the example shows an ice cream cone in which the hemisphere and cone have a radius of 10 inches and the cone has a height of 15 inches. your program must instead prompt for these two values, which are taken from the keyboard as integers: • the hemisphere/cone radius in inches, and
Answers: 3
You know the right 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, 10.02.2021 22:50
Konu
Mathematics, 10.02.2021 22:50