Count a frequency of a particular character in Java
<p>I have the following code. What I want to do is count the frequency of a specific character, but I am unable to do it. Could anyone offer any hints?</p>

<pre><code>import java.io.*;
import java.lang.*;
public class Mywork {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            String str;
            System.out.println("Enter a String:");
            DataInputStream d=new DataInputStream(System.in);
            str=d.readLine();
            int count=0;
            System.out.println("You Entered  "+str);
            char a[]=new char[str.length()];
            int i=0;
            System.out.println("enetr the characte of which frequency is to be count:");
            char c=(char)d.read();
            System.out.println("you entered "+c);
            while(str!=null){
                if(str.charAt(i)==c){
                    count++;
                } else {
                    i++;
                }
                i++;
            }   
            System.out.println("Frequency of character "+c+"is "+count);
        } catch(Exception e){
            System.out.println("I/O Error");
        }
    }
}
</code></pre>
