我需要行保存到一個字符串信息寫入
例:
public function countOccurrences() {
String Message = "Hello, how are you?"
String trim = Mensaje.replaceAll(" ", "");
char[] third = trim.toCharArray();
for (int counter = 0; counter < third.length; counter++) {
char ch = third[counter];
int count = 0;
for (int i = 0; i < third.length; i++) {
if (ch == third[i]) {
count++;
}
}
boolean flag = false;
for (int j = counter - 1; j >= 0; j--) {
if (ch == third[j]) {
flag = true;
}
}
if (!flag) {
trim = "Letra:" + ch + " se repite " + count + " veces ";
// trim is a String where I need to store this information
}
}
預期結果:
- 我需要計算每個字符的出現次數在String :消息
- 在txt文件中保存此信息
例如:
newfile.txt這些內部信息:
H, 2 times
e, 2 times
l, 2 times
o, 3 times
w, 1 times
a, 1 times
r, 1 times
e, 1 times
y, 1 times
u, 1 times
//
我這個嘗試,有人張貼:
修剪修剪= +「\ n「+ ch +」,「+ count +」veces \ n「;
,結果是該文件中:(它更接近)
您好,Howareyou? H,2次e,2次l,2次,3次,1次w,1次 a,1次r,1次y,1次u,1次?,1次
要在@jonnyGold擴大:你能解釋一下什麼結果你想要的,和/或得到期望的結果,爲這個特殊的輸入? –
也許翻譯輸出也將有所幫助...這是一個國際性的網站 – renatoargh
輸出說「信:H重複1次」,「信:O重複3次」等 –