我有以下代码。我想要做的是计算特定字符的频率,但我无法做到。任何人都可以提供任何提示吗?
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");
}
}
}