# probability

string cut = "ahlllaaaa"; i want to get p(a) = 5/9 p(h) = 1/9 p(l) = 3/9

how can i do that ??????????????????????

October 28, 2010 at 12:12 PM

Hello Friend,

Try the following code:

```class Probability{

static int count(char c, String str) {
if (str == null) return 0;
int cnt = 0;
for (int i = 0;; cnt++) {
if ((i = str.indexOf(c,i)+1) == 0) break;
}
return cnt;
}

public static void main(String[] args){
String cut = "ahlllaaaa";
String s = cut.replaceAll((String.format("(.)(?<=(?:(?=\\1).).{0,%d}(?:(?=\\1).))", cut.length())), "");
String st=s.replace(" ","");
int len=cut.length();
char character[]=st.toCharArray();
char ch=' ';
for(int i=0;i<character.length;i++){
ch=character[i];
int c= count(ch,cut);
System.out.println("p("+ch+")="+c+"/"+len);
}
}
}
```

Thanks

Related Tutorials/Questions & Answers:
probability
probability  string cut = "ahlllaaaa"; i want to get p(a) = 5/9 p(h) = 1/9 p(l) = 3/9 how can i do that ??????????????????????   Hello Friend,ADS_TO_REPLACE_1 Try the following code: class Probability{ static int
ModuleNotFoundError: No module named 'probability'
ModuleNotFoundError: No module named 'probability'  Hi, My Python... 'probability' How to remove the ModuleNotFoundError: No module named 'probability' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'CionAttack-Probability'
ModuleNotFoundError: No module named 'CionAttack-Probability'  Hi...: No module named 'CionAttack-Probability' How to remove the ModuleNotFoundError: No module named 'CionAttack-Probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dashboard-Probability'
ModuleNotFoundError: No module named 'Dashboard-Probability'  Hi...: No module named 'Dashboard-Probability' How to remove the ModuleNotFoundError: No module named 'Dashboard-Probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'distributions-probability'
ModuleNotFoundError: No module named 'distributions-probability'  Hi...: No module named 'distributions-probability' How to remove the ModuleNotFoundError: No module named 'distributions-probability' error? Thanks
ModuleNotFoundError: No module named 'distributions-probability'
ModuleNotFoundError: No module named 'distributions-probability'  Hi...: No module named 'distributions-probability' How to remove the ModuleNotFoundError: No module named 'distributions-probability' error? Thanks
ModuleNotFoundError: No module named 'distributions-probability'
ModuleNotFoundError: No module named 'distributions-probability'  Hi...: No module named 'distributions-probability' How to remove the ModuleNotFoundError: No module named 'distributions-probability' error? Thanks
ModuleNotFoundError: No module named 'dsnd-probability'
ModuleNotFoundError: No module named 'dsnd-probability'  Hi, My... named 'dsnd-probability' How to remove the ModuleNotFoundError: No module named 'dsnd-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ekodsnd-probability'
ModuleNotFoundError: No module named 'ekodsnd-probability'  Hi, My... named 'ekodsnd-probability' How to remove the ModuleNotFoundError: No module named 'ekodsnd-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'eko-probability'
ModuleNotFoundError: No module named 'eko-probability'  Hi, My... named 'eko-probability' How to remove the ModuleNotFoundError: No module named 'eko-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'hyh-probability'
ModuleNotFoundError: No module named 'hyh-probability'  Hi, My... named 'hyh-probability' How to remove the ModuleNotFoundError: No module named 'hyh-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'hyh-probability'
ModuleNotFoundError: No module named 'hyh-probability'  Hi, My... named 'hyh-probability' How to remove the ModuleNotFoundError: No module named 'hyh-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'mlend-probability'
ModuleNotFoundError: No module named 'mlend-probability'  Hi, My... named 'mlend-probability' How to remove the ModuleNotFoundError: No module named 'mlend-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'mlend-probability'
ModuleNotFoundError: No module named 'mlend-probability'  Hi, My... named 'mlend-probability' How to remove the ModuleNotFoundError: No module named 'mlend-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'mlnd-probability'
ModuleNotFoundError: No module named 'mlnd-probability'  Hi, My... named 'mlnd-probability' How to remove the ModuleNotFoundError: No module named 'mlnd-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'mnl-probability'
ModuleNotFoundError: No module named 'mnl-probability'  Hi, My... named 'mnl-probability' How to remove the ModuleNotFoundError: No module named 'mnl-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'mnl-probability'
ModuleNotFoundError: No module named 'mnl-probability'  Hi, My... named 'mnl-probability' How to remove the ModuleNotFoundError: No module named 'mnl-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'om-probability'
ModuleNotFoundError: No module named 'om-probability'  Hi, My... named 'om-probability' How to remove the ModuleNotFoundError: No module named 'om-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'om-probability'
ModuleNotFoundError: No module named 'om-probability'  Hi, My... named 'om-probability' How to remove the ModuleNotFoundError: No module named 'om-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'om-probability'
ModuleNotFoundError: No module named 'om-probability'  Hi, My... named 'om-probability' How to remove the ModuleNotFoundError: No module named 'om-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ot-probability'
ModuleNotFoundError: No module named 'ot-probability'  Hi, My... named 'ot-probability' How to remove the ModuleNotFoundError: No module named 'ot-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'probability-and-distributions'
ModuleNotFoundError: No module named 'probability-and-distributions'  ...: No module named 'probability-and-distributions' How to remove the ModuleNotFoundError: No module named 'probability-and-distributions' error
ModuleNotFoundError: No module named 'probability-distributions'
ModuleNotFoundError: No module named 'probability-distributions'  Hi...: No module named 'probability-distributions' How to remove the ModuleNotFoundError: No module named 'probability-distributions' error? Thanks
ModuleNotFoundError: No module named 'probability-dsnd-2019'
ModuleNotFoundError: No module named 'probability-dsnd-2019'  Hi...: No module named 'probability-dsnd-2019' How to remove the ModuleNotFoundError: No module named 'probability-dsnd-2019' error? Thanks   Hi
ModuleNotFoundError: No module named 'progenitor-probability'
ModuleNotFoundError: No module named 'progenitor-probability'  Hi...: No module named 'progenitor-probability' How to remove the ModuleNotFoundError: No module named 'progenitor-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'pu-probability'
ModuleNotFoundError: No module named 'pu-probability'  Hi, My... named 'pu-probability' How to remove the ModuleNotFoundError: No module named 'pu-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pu-probability'
ModuleNotFoundError: No module named 'pu-probability'  Hi, My... named 'pu-probability' How to remove the ModuleNotFoundError: No module named 'pu-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pu-probability'
ModuleNotFoundError: No module named 'pu-probability'  Hi, My... named 'pu-probability' How to remove the ModuleNotFoundError: No module named 'pu-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-probability'
ModuleNotFoundError: No module named 'python-probability'  Hi, My... named 'python-probability' How to remove the ModuleNotFoundError: No module named 'python-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'qh-probability'
ModuleNotFoundError: No module named 'qh-probability'  Hi, My... named 'qh-probability' How to remove the ModuleNotFoundError: No module named 'qh-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'qh-probability'
ModuleNotFoundError: No module named 'qh-probability'  Hi, My... named 'qh-probability' How to remove the ModuleNotFoundError: No module named 'qh-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'rt-probability'
ModuleNotFoundError: No module named 'rt-probability'  Hi, My... named 'rt-probability' How to remove the ModuleNotFoundError: No module named 'rt-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tensorflow-probability'
ModuleNotFoundError: No module named 'tensorflow-probability'  Hi...: No module named 'tensorflow-probability' How to remove the ModuleNotFoundError: No module named 'tensorflow-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'testuda-probability'
ModuleNotFoundError: No module named 'testuda-probability'  Hi, My... named 'testuda-probability' How to remove the ModuleNotFoundError: No module named 'testuda-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'udacity-probability'
ModuleNotFoundError: No module named 'udacity-probability'  Hi, My... named 'udacity-probability' How to remove the ModuleNotFoundError: No module named 'udacity-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'Abdullah-probability'
ModuleNotFoundError: No module named 'Abdullah-probability'  Hi...: No module named 'Abdullah-probability' How to remove the ModuleNotFoundError: No module named 'Abdullah-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'aserna-probability'
ModuleNotFoundError: No module named 'aserna-probability'  Hi, My... named 'aserna-probability' How to remove the ModuleNotFoundError: No module named 'aserna-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'bonifacio-probability'
ModuleNotFoundError: No module named 'bonifacio-probability'  Hi...: No module named 'bonifacio-probability' How to remove the ModuleNotFoundError: No module named 'bonifacio-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'chaoyi-probability'
ModuleNotFoundError: No module named 'chaoyi-probability'  Hi, My... named 'chaoyi-probability' How to remove the ModuleNotFoundError: No module named 'chaoyi-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'CionAttack-Probability'
ModuleNotFoundError: No module named 'CionAttack-Probability'  Hi...: No module named 'CionAttack-Probability' How to remove the ModuleNotFoundError: No module named 'CionAttack-Probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'Dashboard-Probability'
ModuleNotFoundError: No module named 'Dashboard-Probability'  Hi...: No module named 'Dashboard-Probability' How to remove the ModuleNotFoundError: No module named 'Dashboard-Probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'distribution-of-probability'
ModuleNotFoundError: No module named 'distribution-of-probability'  ...: No module named 'distribution-of-probability' How to remove the ModuleNotFoundError: No module named 'distribution-of-probability' error? Thanks
ModuleNotFoundError: No module named 'distributions-of-probability'
ModuleNotFoundError: No module named 'distributions-of-probability'  ...: No module named 'distributions-of-probability' How to remove the ModuleNotFoundError: No module named 'distributions-of-probability' error
ModuleNotFoundError: No module named 'distributions-probability'
ModuleNotFoundError: No module named 'distributions-probability'  Hi...: No module named 'distributions-probability' How to remove the ModuleNotFoundError: No module named 'distributions-probability' error? Thanks
ModuleNotFoundError: No module named 'dsnd-probability'
ModuleNotFoundError: No module named 'dsnd-probability'  Hi, My... named 'dsnd-probability' How to remove the ModuleNotFoundError: No module named 'dsnd-probability' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ekodsnd-probability'
ModuleNotFoundError: No module named 'ekodsnd-probability'  Hi, My... named 'ekodsnd-probability' How to remove the ModuleNotFoundError: No module named 'ekodsnd-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'eko-probability'
ModuleNotFoundError: No module named 'eko-probability'  Hi, My... named 'eko-probability' How to remove the ModuleNotFoundError: No module named 'eko-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'example-probability'
ModuleNotFoundError: No module named 'example-probability'  Hi, My... named 'example-probability' How to remove the ModuleNotFoundError: No module named 'example-probability' error? Thanks   Hi
ModuleNotFoundError: No module named 'gb-probability'
ModuleNotFoundError: No module named 'gb-probability'  Hi, My... named 'gb-probability' How to remove the ModuleNotFoundError: No module named 'gb-probability' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'geomatics-probability'
ModuleNotFoundError: No module named 'geomatics-probability'  Hi...: No module named 'geomatics-probability' How to remove the ModuleNotFoundError: No module named 'geomatics-probability' error? Thanks   Hi