Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Simple Search program - Java Code Bank


Simple Search program
This program asks for a string(keyword) and searches for it in the text entered.
                import java.io.*;
class stringcatch
{
    public static void main(String args[])throws IOException
    {
        BufferedReader xy=new BufferedReader(new InputStreamReader(System.in));
        String k,s,ssub,ksub;
        int slen,klen,subn=0,kubn=0;
        k="";
        s="";
        System.out.print("Enter Text:");
        s=xy.readLine();
        slen=s.length();
        System.out.print("Enter keyword to be searched:");
        k=xy.readLine();
        klen=k.length();
        ssub="";
        String word="";
        int no=0;
        for(int i5=0;i5<slen-1;i5++)
        {
            ssub=s.substring(i5,i5+1);
            if(ssub.equals(" ")==false)
            {
                word=word+ssub+"";
            }
            else
            {
                
                if(word.equals(k)==true)
                {
                    no=no+1;
                                        
                }
                word="";                
            }
        }
        System.out.println("No. of times:"+no);
    }
}
            
Comments
Sorry but there are no comments to display