I tried the different methods that you advise here but cant find the solution... Can anyone help?
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{
threads.add(new Thread(new t1()));
threads.add(new Thread(new t2()));
threads.add(new Thread(new t3()));
threads.add(new Thread(new t4()));
threads.add(new Thread(new t5()));
}
public static void main(String[] args) {
}
public static class t1 implements Runnable{
public void run(){
while(true){}
}
}
public static class t2 implements Runnable{
public void run(){
try{Thread.sleep(500);}
catch(InterruptedException e){System.out.println("InterruptedException");}
}
}
public static class t3 implements Runnable{
public void run(){
try{
while (!Thread.interrupted()) {
System.out.println("Hurray");
Thread.sleep(500);
}
}
catch(Exception e){}
}
}
public static class t4 extends Thread implements Message{
private boolean isWarned = false;
@Override
public void showWarning() {
isWarned = true;
}
@Override
public void run() {
while (this.isAlive()) {
if (this.isWarned) {
return; // "break" also works
}
}
}
}
public static class t5 implements Runnable{
public void run(){
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = 0;
try{
while(true){
String s = reader.readLine();
if(s.equals("N"))
break;
n += Integer.parseInt(s);
}
System.out.println(n);
}
catch (IOException e) {
}
}
}
}