Created
August 7, 2023 23:12
-
-
Save Raf0707/a0d08c2cc41566936f44c138adc351ea to your computer and use it in GitHub Desktop.
CounterLetter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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