package ru.job4j.threads;

/**
 * class WordsSpaces
 */
public class WordsSpaces {
    public static void main(String[] args) throws InterruptedException {
        String string = "Some words with some spaces";
        new Thread(new WordsCalc(string)).start();
        new Thread(new SpacesCalc(string)).start();
    }
}

class WordsCalc implements Runnable {

    private String str;

    WordsCalc(String str) {
        this.str = str;
    }

    private int wordCalc(String str) {
        String[] strings = str.split(" ");
        return strings.length;
    }

    @Override
    public void run() {
        System.out.println(String.format("The number of words: %s", wordCalc(str)));
    }
}

class SpacesCalc implements Runnable {

    private String str;

    SpacesCalc(String str) {
        this.str = str;
    }

    private int wordCalc(String str) {
        int result = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == ' ') {
                result++;
            }
        }
        return result;
    }

    @Override
    public void run() {
        System.out.println(String.format("The number of spaces: %s", wordCalc(str)));
    }
}

@@ -76,16 +76,527 @@
 paces %7B%0A
+%0A    private static void calculateWordsSpaces(String str) throws InterruptedException %7B%0A        System.out.println(%22Start calculating%22);%0A        System.out.println(str);%0A        Thread wordCalcThread = new Thread(new WordsCalc(str));%0A        Thread spaceCalcThread = new Thread(new SpacesCalc(str));%0A        wordCalcThread.start();%0A        spaceCalcThread.start();%0A        Thread.sleep(1000);%0A        wordCalcThread.interrupt();%0A        spaceCalcThread.interrupt();%0A        System.out.println(%22Finish%22);%0A    %7D%0A%0A
     publ
@@ -727,92 +727,36 @@
     
-new Thread(new WordsCalc(string)).start();%0A        new Thread(new 
+calculateWords
 Spaces
-Calc
 (string)
 ).st
@@ -755,17 +755,8 @@
 ing)
-).start()
 ;%0A  
@@ -1035,32 +1035,123 @@
 ic void run() %7B%0A
+        Thread thread = Thread.currentThread();%0A        if (!thread.isInterrupted()) %7B%0A    
         System.o
@@ -1211,32 +1211,42 @@
 ordCalc(str)));%0A
+        %7D%0A
     %7D%0A%7D%0A%0Aclass S
@@ -1625,32 +1625,123 @@
 ic void run() %7B%0A
+        Thread thread = Thread.currentThread();%0A        if (!thread.isInterrupted()) %7B%0A    
         System.o
@@ -1810,16 +1810,28 @@
 str)));%0A
+        %7D%0A
     %7D%0A
-
 %7D%0A
+%0A%0A

task 1017 waiting output