Notice


AWT and SWING will be covered soon !

Tuesday, September 22, 2009

Search Number of Occurrences in String

image

import java.util.Scanner;

public class demo{
    public static void main(String args[])
    {
        char input;
        String str_input;
        char veb;
        int count=0;
        String str="Apple";
        Scanner scan=new Scanner(System.in);
        System.out.println("Enter a String");
        str=scan.nextLine();
        System.out.println("enter the Charchter you want to Search");
        str_input=scan.next();
        input=str_input.charAt(0);
        for(int i=0;i<str.length();i++)
        {
            veb=str.charAt(i);
            if(input==veb)
            {
                count++;
            }       
        }
            System.out.println("Occurances : "+count);
    }
}

No comments:

Post a Comment