Wednesday, March 24, 2021

Java program to find number of occurrences of a character in a string.

 // 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);

  }

}


Java Regex

You are updating the username policy on your company's internal networking platform. According to the policy, a username is considered v...