klasscho

Untitled

Mar 4th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package com.company;
  2. import java.util.HashSet;
  3. import java.util.LinkedHashSet;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Main {
  8. public static String ReadLine(){
  9. String inputLine;
  10. Boolean isNotCorrect = false;
  11. do {
  12. Scanner in = new Scanner(System.in);
  13. System.out.println("Пожалуйста, введите предложение: ");
  14. inputLine = in.nextLine();
  15. isNotCorrect = false;
  16. if (inputLine.equals(null) || inputLine.equals(" ")) {
  17. System.out.println("Вы ввели пустое преложение. Попробуйте еще раз!");
  18. isNotCorrect = true;
  19. }
  20. System.out.println(inputLine);
  21. } while (isNotCorrect);
  22. return (inputLine);
  23. }
  24.  
  25. public static void LineResult (int VowelsNum, int ConsonantsNum, LinkedHashSet<Character> ActualVowels, LinkedHashSet<Character> ActualConsonants){
  26. int i;
  27. if ((VowelsNum == 0)&&(ConsonantsNum == 0)) {
  28. System.out.println("В строке отсутвуют буквы.");
  29. }
  30. else{
  31. if (VowelsNum == 0) {
  32. System.out.println("В строке отсутвуют гласные.");
  33. }
  34. if (ConsonantsNum == 0) {
  35. System.out.println("В строке отсутвуют согласные.");
  36. }
  37. }
  38. System.out.printf("Количество гласных: %d\n", VowelsNum);
  39. System.out.printf("Количество согласных: %d\n", ConsonantsNum);
  40. }
  41.  
  42. public static void LineCheck (String inputLine) {
  43. HashSet<Character> Vowels = new HashSet<Character>();
  44. String Vowels$1 = "аоуэыяеёюиАОУЭЫЯЕЁИ";
  45. for (int i = 0; i < Vowels$1.length(); i++) {
  46. Vowels.add(Vowels$1.charAt(i));
  47. }
  48. HashSet<Character> Consonants = new HashSet<Character>();
  49. String Consonants$1 = "йцкнгшщзхъфвпрлджчсмтьбЙЦКНГШЩЗХЪФВПРЛДЖЧСМТЬБ";
  50. for (int i = 0; i < Consonants$1.length(); i++) {
  51. Consonants.add(Consonants$1.charAt(i));
  52. }
  53. LinkedHashSet<Character> ActualVowels = new LinkedHashSet<>();
  54. LinkedHashSet<Character> ActualConsonants = new LinkedHashSet<>();
  55. int VowelsNum = 0;
  56. int ConsonantsNum = 0;
  57. for (int i = 0; i < inputLine.length(); i++){
  58. if (Vowels.contains(inputLine.charAt(i))){
  59. VowelsNum++;
  60. ActualConsonants.add(inputLine.charAt(i));
  61. }
  62. if (Consonants.contains(inputLine.charAt(i))){
  63. ConsonantsNum++;
  64. ActualConsonants.add(inputLine.charAt(i));
  65. }
  66. }
  67. LineResult(VowelsNum, ConsonantsNum, ActualVowels, ActualConsonants);
  68. }
  69.  
  70. public static void main (String[]args) throws Exception {
  71. System.out.println("Данная программа производит подсчет символов в веденном предложении.");
  72. String inputLine;
  73. inputLine = ReadLine();
  74. LineCheck(inputLine.toLowerCase());
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment