Skip to content

Instantly share code, notes, and snippets.

@Raf0707
Created August 7, 2023 23:12
Show Gist options
  • Save Raf0707/a0d08c2cc41566936f44c138adc351ea to your computer and use it in GitHub Desktop.
Save Raf0707/a0d08c2cc41566936f44c138adc351ea to your computer and use it in GitHub Desktop.
CounterLetter
import java.util.HashMap;
import java.util.Scanner;
public class CounterLetter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String word = sc.nextLine();
HashMap<Character, Integer> counter = new HashMap<>();
// количество букв в слове
for (int i = 0; i < word.length(); i++) {
char letter = word.charAt(i);
counter.put(letter, counter.getOrDefault(letter, 0) + 1);
}
// больше трех раз
for (char letter : counter.keySet()) {
int count = counter.get(letter);
if (count >= 3) {
System.out.println("В слове " + word + " " + count + " букв(a) " + letter);
break;
}
System.out.println(letter + ": " + count);
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment