Advertisement
PonaFly

Untitled

Feb 27th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class main {
  4. public static void main(String args[]) {
  5. Scanner sc = new Scanner(System.in);
  6. String msg = sc.nextLine();
  7. Message message = new Message(msg);
  8. System.out.println(message.countWords());
  9. System.out.println(message.reverse());
  10. System.out.println(message.count('a'));
  11. System.out.println(message.serial());
  12. System.out.println(message.number());
  13. }
  14. }
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. class Message {
  22. public String str;
  23.  
  24. public Message(String str) {
  25. this.str = str;
  26. }
  27.  
  28. public int countWords() {
  29. return str.split(" ").length;
  30. }
  31. public String reverse() {
  32. return new StringBuilder(str).reverse().toString();
  33. }
  34. public int count(char c) {
  35. int count = 0;
  36. for (char ch: str.toCharArray()) {
  37. if (ch == c) {
  38. count++;
  39. }
  40. }
  41. return count;
  42. }
  43. public String serial() {
  44. String[] arr = str.toLowerCase().split(" ");
  45. for (int i = 0; i < str.length(); i++) {
  46. if (arr[i].equals("серия")) {
  47. return arr[i + 1];
  48. }
  49. }
  50. return null;
  51. }
  52. public String number() { // возвращает номер (номер находится после №, но после № может пробела и не быть)
  53. String[] arr = str.split(" ");
  54. for (int i = 0; i < str.length(); i++) {
  55. if (arr[i].startsWith("№")) {
  56. if (arr[i].length() > 1) {
  57. return arr[i];
  58. }
  59. else {
  60. return arr[i + 1];
  61. }
  62. }
  63. }
  64. return null;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement