i've made the following program that count how many times the input character is appeared in a string.
import java.io.*;
class strngcls{
public static void main (String args[])throws IOException{
String s1,s2;
char ch;
InputStreamReader ir = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ir);
System.out.println ("Type any Sentence: ");
s1=br.readLine();
ch = 'X';
System.out.println (charcount(s1,ch));
}
static int charcount (String st, char c){
int count=0;
for (int i=0;i<st.length(); i++)
if (c==st.charAt(i))
count++;
return count;
}
}
This program is counting how many times a capital 'X' is appeared in a string , i want my program to count capital and small both....i applied is.UpperCase and is.LowerCase but it is not working