The program currently reads the output from the first thread and adds it to the list of the second thread e.g.
Input
a
b
c
Output
a b c
Input
a
b
Output
a b ca b
edit: I got rid of line 33, didn't notice line 9 originally
package com.codegym.task.task16.task1629;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution {
public static volatile BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws InterruptedException {
Read3Strings t1 = new Read3Strings();
//write your code here
t1.start();
t1.join();
t1.printResult();
Read3Strings t2 = new Read3Strings();
t2.start();
t2.join();
t2.printResult();
}
//write your code here
public static class Read3Strings extends Thread{
static ArrayList<String> list = new ArrayList<>();
@Override
public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i<3; i++){
try {
list.add(reader.readLine());
list.add(" ");
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void printResult(){
for (int i =0; i<list.size()-1; i++){
System.out.print(list.get(i));
}
}
}
}