java - countChars - So close, yet so far -
i feel there, i've starred blind after trying know(which isn't lot.)
alright, trying input string method should read , give me numbers of each character or first. i'm lost. please help.
public class sam { private static string countchars; public static void main(string[] args) { system.out.println(countchars); } static int countchars(string str, char searchchar) { // count number of times searchchar occurs in // str , return result. int i; // position in string, str. char ch; // character in string. int count; // number of times searchchar has been found in str. count = 0; (i = 0; < str.length(); i++) { ch = str.charat(i); // i-th character in str. if (ch == searchchar) { count++; } } return count; }
}
best regards, sam
you not correctly calling countchars()
function in main()
function.
you use following example
system.out.println(countchars("hello, world", 'o'));
Comments
Post a Comment