0
所以我創建非常簡單的函數來計算重複單詞的概率,但我發現概率數組並沒有被初始化?總是例如概率由0 :概率數學總是輸出零?
String original = "abcabd";
String n = "abcd";
int count = 0;
float Probabilty[] = new float[n.length()];
for(int i = 0 ; i < n.length() ; i++){
for(int j =0 ; j < original.length() ; j++){
if (n.charAt(i)== original.charAt(j)){
count = count +1;
}
}
Probabilty[i] = count/original.length();
System.out.println(Probabilty[i]);
count = 0;
}
陣列不是問題。使用調試器。製作[mcve] –