行を文字列に保存する必要があります
元:
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: Message 内の各文字の出現回数をカウントする必要があります。
- この情報を 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 + ", " + カウント + " veces \n";
結果はファイル内で次のようになりました:(それは近いです)
こんにちは元気ですか?H、2回e、2回l、2回o、3回、、1回w、1回a、1回r、1回y、1回u、1回?、1回