package ru.napadovskiyB;


import java.util.StringTokenizer;

/**
 * Package of CollectionPro finalTask.
 * Main class for order book.
 * @author Napadovskiy Bohdan
 * @version 1.0
 * @since 09.08.2017
 */
public class CheckString  {

    /**
     * Method calculate space in string.
     * @param stringForCheck string.
     * @return result.
     */
    public Thread calcSpace(String  stringForCheck) {
        return new Thread() {
            @Override
            public void run() {
                if (isInterrupted()) {
                    interrupted();
                    return;
                }
                String newString = stringForCheck.replaceAll(" ", "").trim();

                int result = stringForCheck.length() - newString.length();

                System.out.println(result);
            }
        };

    }


    /**
     *  Method calculate words in string.
     * @param stringForCheck string for check.
     * @return result
     */
    public Thread calcWorlds(String  stringForCheck) {
        return new Thread() {
            @Override
            public void run() {
                int count = 0;
                if (isInterrupted()) {
                    interrupted();
                    return;
                }

                StringTokenizer stringTokenizer = new StringTokenizer(stringForCheck);

                while (stringTokenizer.hasMoreTokens()) {
                    stringTokenizer.nextElement();
                    count++;

                }
                System.out.println(count);
            }
        };
    }

    /**
     * Main thread.
     * @return thread.
     */
    public Thread mainThread() {
        return new Thread() {

            private String  newString = "а баба галамага тест";

            private final int timeStop = 1000;

            @Override
            public void run() {

                Thread firstThread = calcSpace(newString);
                Thread secondThread = calcWorlds(newString);

                try {
                    firstThread.start();
                    secondThread.start();

                    firstThread.join(timeStop);
                    secondThread.join(timeStop);

                    firstThread.interrupt();
                    secondThread.interrupt();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
    }

    /**
     * Main method.
     * @param args array string.
     */
    public static void main(String[] args) {
        System.out.println("Start");
        CheckString checkString = new CheckString();
        Thread mainThread = checkString.mainThread();
        mainThread.start();

        try {
            mainThread.join();


        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        mainThread.interrupt();
        System.out.println("Finish");

    }

}




@@ -623,71 +623,129 @@
     
-String newString = stringForCheck.replaceAll(%22 %22, %22%22).trim
+char checkChar = ' ';%0A                int result = 0;%0A                char%5B%5D charsString = stringForCheck.toCharArray
 ();%0A
-%0A
     
@@ -760,67 +760,164 @@
     
-int result = stringForCheck.length() - newString.length();%0A
+for (char tmpChar : charsString) %7B%0A                    if (tmpChar == checkChar) %7B%0A                        result++;%0A                    %7D%0A                %7D
 %0A   
@@ -2910,18 +2910,16 @@
 join();%0A
-%0A%0A
         

update 1. Cчитать количество и пробелом в тексте[#21741]