.
package com.codegym.task.task16.task1632;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static{
A a=new A();
B b=new B();
C c=new C();
D d=new D();
E e = new E();
Thread thread1=new Thread(a);
threads.add(thread1);
Thread thread2=new Thread(b);
threads.add(thread2);
Thread thread3=new Thread(c);
threads.add(thread3);
Thread thread4=new Thread(d);
threads.add(thread4);
Thread thread5 = new Thread(e);
threads.add(thread5);
}
public static void main(String[] args) {
for(Thread abc : threads){
abc.start();
}
}
public static class A extends Thread{
public void run(){
while(true){
}
}
}
public static class B extends Thread{
public void run(){
try {
throw new InterruptedException();
}catch (InterruptedException e){
System.out.println("InterruptedException");
}
}
}
public static class C extends Thread{
public void run(){
try {while(true) {
System.out.println("Hurray");
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static class D extends Thread implements Message{
@Override
public void showWarning() {
this.interrupt();
}
@Override
public void run() {
while(isAlive()){
showWarning();
}
}
}
public static class E extends Thread{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int num,sum=0;
public void run(){
try {
while(true) {
String a = reader.readLine();
if (a.equals("N")) {
System.out.println(sum);
break;
}
num = Integer.parseInt(a);
sum = sum + num;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}