Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class main {
- public static void main(String args[]) {
- Scanner sc = new Scanner(System.in);
- String msg = sc.nextLine();
- Message message = new Message(msg);
- System.out.println(message.countWords());
- System.out.println(message.reverse());
- System.out.println(message.count('a'));
- System.out.println(message.serial());
- System.out.println(message.number());
- }
- }
- class Message {
- public String str;
- public Message(String str) {
- this.str = str;
- }
- public int countWords() {
- return str.split(" ").length;
- }
- public String reverse() {
- return new StringBuilder(str).reverse().toString();
- }
- public int count(char c) {
- int count = 0;
- for (char ch: str.toCharArray()) {
- if (ch == c) {
- count++;
- }
- }
- return count;
- }
- public String serial() {
- String[] arr = str.toLowerCase().split(" ");
- for (int i = 0; i < str.length(); i++) {
- if (arr[i].equals("серия")) {
- return arr[i + 1];
- }
- }
- return null;
- }
- public String number() { // возвращает номер (номер находится после №, но после № может пробела и не быть)
- String[] arr = str.split(" ");
- for (int i = 0; i < str.length(); i++) {
- if (arr[i].startsWith("№")) {
- if (arr[i].length() > 1) {
- return arr[i];
- }
- else {
- return arr[i + 1];
- }
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement