public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
public static void main(String[] args) {
threads.add(new TestThread());
threads.add(new TestThread2());
threads.add(new TestThread3());
threads.add(new TestThread4());
threads.add(new TestThread5());
}
public static class TestThread extends Thread {
public void run() {
while (true) {
}
}
}
public static class TestThread2 extends Thread {
public void run() {
try {
throw new InterruptedException();
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class TestThread3 extends Thread {
public void run() {
try {
while (true) {
System.out.println("Ура");
Thread.currentThread().sleep(500);
}
} catch (InterruptedException e) {
}
}
}
public static class TestThread4 extends Thread implements Message {
public void run() {
showWarning();
}
public void showWarning() {
Thread.currentThread().interrupt();
}
}
public static class TestThread5 extends Thread {
public void run() {
int sum = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
while(true) {
String str = reader.readLine();
if (!str.equals("N")) {
sum += Integer.valueOf(str);
} else {
System.out.println(sum);
break;
}
}
} catch (IOException e) {
}
}
}
}
package com.javarush.task.task16.task1632;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
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);
public static void main(String[] args) {
threads.add(new TestThread());
threads.add(new TestThread2());
threads.add(new TestThread3());
threads.add(new TestThread4());
threads.add(new TestThread5());
}
public static class TestThread extends Thread {
public void run() {
while (true) {
}
}
}
public static class TestThread2 extends Thread {
public void run() {
try {
throw new InterruptedException();
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class TestThread3 extends Thread {
public void run() {
try {
while (true) {
System.out.println("Ура");
Thread.currentThread().sleep(500);
}
} catch (InterruptedException e) {
}
}
}
public static class TestThread4 extends Thread implements Message {
public void run() {
showWarning();
}
public void showWarning() {
Thread.currentThread().interrupt();
}
}
public static class TestThread5 extends Thread {
public void run() {
int sum = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
while(true) {
String str = reader.readLine();
if (!str.equals("N")) {
sum += Integer.valueOf(str);
} else {
System.out.println(sum);
break;
}
}
} catch (IOException e) {
}
}
}
}