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

Write about Decision making and Branching statements in Java with Examples?

Decision making and Branching statements:    A java program is a set of statements which are normally executed sequentially same in the order in which they appear. Wh...

Write about Decission making & looping in Java With Example?

Decision making & looping:                                               &...

Write about Jumps in loops in java

Jumps in loops: Break : [jumping of out of a loop] Break is used to come out of a loop, an early exists from a loop can be accomplished by using break statement. The break statement can be use...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item