PROGRAM FOR FINDING NUMBER OF OCCURENCES OFA STRING IN GIVEN STRING

 import java.lang.*; class number {             int c,sublen,off;             number( )             {                         ...

 import java.lang.*;
class number
{
            int c,sublen,off;
            number( )
            {
                        c=0;
            }
        void occur(String a,String b)
            {
                        sublen=b.length( );
                        off=a.indexOf(b,0);
                         while(off!=-1)
                        {
                                     c++;
                                     off=off+sublen;
                                     off=a.indexOf(b,off);
                        }
                        System.out.println("number of occurenes" +c);
            }
}
class count
{
  public static void main(String args[ ])
    {
            String str="this is java";
            String sub="is";
            System.out.println("given String="+ str);
            System.out.println("subString is="+ sub);
            number obj=new number( );
            obj.occur(str,sub);
    }
}



OUTPUT:

given String=this is java

subString is=is


number of occurenes2

Related

Java 1845065239422831316

Post a Comment

emo-but-icon

item