// JAVA PROGRAM TO FIND NUMBER OF OCCURANCES OF A CHARACTER IN A STRING
public class Main
{
public static void main (String[]args)
{
String str = "Hello world";
int count = 0;
for (int i = 0; i < str.length (); i++)
{
if (str.charAt (i) == 'l') //to find occurance of character l
count++;
}
System.out.print (count);
}
}
No comments:
Post a Comment