Last active
June 11, 2016 21:30
-
-
Save josinSbazin/65fba92be0e67ed993751a22e41849ec to your computer and use it in GitHub Desktop.
level10.lesson11.home05;
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
package com.javarush.test.level10.lesson11.home05; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
/* Количество букв | |
Ввести с клавиатуры 10 строчек и подсчитать в них количество различных букв (для 33 букв алфавита). Вывести результат на экран. | |
Пример вывода: | |
а 5 | |
б 8 | |
в 3 | |
г 7 | |
д 0 | |
… | |
я 9 | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws Exception { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
//алфавит | |
String abc = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; | |
char[] abcArray = abc.toCharArray(); | |
ArrayList<Character> alphabet = new ArrayList<Character>(); | |
for (int i = 0; i < abcArray.length; i++) { | |
alphabet.add(abcArray[i]); | |
} | |
//ввод строк | |
ArrayList<String> list = new ArrayList<String>(); | |
for (int i = 0; i < 10; i++) { | |
String s = reader.readLine(); | |
list.add(s.toLowerCase()); | |
} | |
/* | |
//Первый вариант с Collections | |
ArrayList <Character> chars = new ArrayList<Character>(); | |
for (String s : list) { | |
for (int i = 0; i < s.length(); i++) { | |
chars.add(s.toCharArray()[i]); | |
} | |
} | |
for (char c : alphabet) { | |
System.out.println(c+" "+Collections.frequency(chars, c)); | |
}*/ | |
//Второй вариант с циклами | |
String str = list.toString(); | |
for (int i = 0; i < alphabet.size(); i++) { | |
int count = 0; | |
for (int j = 0; j < str.length(); j++) { | |
if (alphabet.get(i)==str.charAt(j)) count++; | |
} | |
System.out.println(alphabet.get(i)+" "+count); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment